From 483bfef1fc236b0827e4d8ff28ac9aa287ff8468 Mon Sep 17 00:00:00 2001
From: "Stephen R. van den Berg" <srb@cuci.nl>
Date: Wed, 5 May 2021 00:07:55 +0200
Subject: [PATCH] pgsql: Verify objects are still live at these points.

---
 lib/modules/Sql.pmod/pgsql.pike      | 6 ++++--
 lib/modules/Sql.pmod/pgsql_util.pmod | 3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/modules/Sql.pmod/pgsql.pike b/lib/modules/Sql.pmod/pgsql.pike
index 5c0d79e341..70fce69555 100644
--- a/lib/modules/Sql.pmod/pgsql.pike
+++ b/lib/modules/Sql.pmod/pgsql.pike
@@ -493,8 +493,10 @@ private void waitauthready() {
 }
 
 protected void destroy() {
-  proxy.unnamedstatement = 0;		// Forget about pending statements
-  destruct(proxy);
+  if (proxy) {
+    proxy.unnamedstatement = 0;		// Forget about pending statements
+    destruct(proxy);
+  }
 }
 
 //! For PostgreSQL this function performs the same function as @[resync()].
diff --git a/lib/modules/Sql.pmod/pgsql_util.pmod b/lib/modules/Sql.pmod/pgsql_util.pmod
index 8d94038f76..1881a1ef3e 100644
--- a/lib/modules/Sql.pmod/pgsql_util.pmod
+++ b/lib/modules/Sql.pmod/pgsql_util.pmod
@@ -712,7 +712,8 @@ outer:
     };
     PD("Connect error %s\n", describe_backtrace(err));
     catch(destruct(pgsqlsess->waitforauthready));
-    destruct(this);
+    if (this)
+      destruct(this);
   }
 
   private string _sprintf(int type) {
-- 
GitLab