From 6c48829d4080f29626f7a2ff38e29c4d25ec0566 Mon Sep 17 00:00:00 2001 From: "Stephen R. van den Berg" <srb@cuci.nl> Date: Sun, 28 Feb 2016 00:14:43 +0100 Subject: [PATCH] pgsql: Move real close into the destructor. Also destruct the conxion object directly, to make sure that the filedescriptors actually get closed. --- lib/modules/Sql.pmod/pgsql.pike | 5 ++--- lib/modules/Sql.pmod/pgsql_util.pmod | 30 +++++++++++++++------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/modules/Sql.pmod/pgsql.pike b/lib/modules/Sql.pmod/pgsql.pike index e20156f456..e4ee797793 100644 --- a/lib/modules/Sql.pmod/pgsql.pike +++ b/lib/modules/Sql.pmod/pgsql.pike @@ -1204,8 +1204,7 @@ private void procmessage() { termlock=(termthread=Thread.Mutex())->lock(); c->close(); termthread->lock(1); - c=0; - destruct(waitforauthready); + destruct(c);destruct(waitforauthready); } protected void destroy() { @@ -1262,7 +1261,7 @@ private int reconnect() { termlock=(termthread=Thread.Mutex())->lock(); c->close(); termthread->lock(1); - c=0; + destruct(c); PD("Flushing old cache\n"); foreach(_prepareds;;mapping tp) m_delete(tp,"preparedname"); diff --git a/lib/modules/Sql.pmod/pgsql_util.pmod b/lib/modules/Sql.pmod/pgsql_util.pmod index ce5b97cedb..b554a60946 100644 --- a/lib/modules/Sql.pmod/pgsql_util.pmod +++ b/lib/modules/Sql.pmod/pgsql_util.pmod @@ -338,9 +338,9 @@ outer: } final int close() { - int ret=0; - if(!closenext && nostash) - { Thread.MutexKey lock=i->fillreadmux->lock(); + if(!closenext && nostash) { + closenext=1; + Thread.MutexKey lock=i->fillreadmux->lock(); if(i->fillread) { // Delayed close() after flushing the output buffer i->fillread.signal(); i->fillread=0; @@ -348,20 +348,22 @@ outer: lock=0; PD("%d>Delayed close, flush write\n",socket->query_fd()); i->read_cb(socket->query_id(),0); - closenext=1; - } else { - destruct(nostash); - PD("%d>Close socket\n",socket->query_fd()); - ret=socket->close(); - foreach(closecallbacks;function(void|mixed:void) closecb;) - closecb(); - closecallbacks=(<>); - } - return ret; + return 0; + } else + return -1; } protected void destroy() { - catch(close()); // Exceptions don't work inside destructors + if(nostash) { + catch { + destruct(nostash); + PD("%d>Close socket\n",socket->query_fd()); + socket->close(); + foreach(closecallbacks;function(void|mixed:void) closecb;) + closecb(); + closecallbacks=(<>); + }; + } connectfail=0; } -- GitLab