aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2000-07-27 19:44:01 +0000
committerBruce Momjian <bruce@momjian.us>2000-07-27 19:44:01 +0000
commite3b440066798b6692c79613783b7bc2cdeac8f82 (patch)
treee23d861fec2397ebb8ef6a939cf788889fce9819
parent1ee0d4a9920fc0617c41f109873f71cacc772417 (diff)
downloadpostgresql-e3b440066798b6692c79613783b7bc2cdeac8f82.tar.gz
postgresql-e3b440066798b6692c79613783b7bc2cdeac8f82.zip
Here is a bug and patch to fix it. I have tested this bug and fix on
FreeBSD/Intel and DecUX/Alpha machines. The bug appears in postgresql 6.5.3 and 7.0.2. Can someone please review it and apply it to the source tree? Sometimes when the postgres connection dies it is necessary to attempt to reconnect. Calling the pgconnection::Connect method in a derived class leaks memory because it does not clear the current connection (if there is one). These patches ensures that any open connections are closed before attempting to open a new one. -Michael Richards
-rw-r--r--src/interfaces/libpq++/pgconnection.cc20
-rw-r--r--src/interfaces/libpq++/pgconnection.h3
2 files changed, 20 insertions, 3 deletions
diff --git a/src/interfaces/libpq++/pgconnection.cc b/src/interfaces/libpq++/pgconnection.cc
index 321d41f0304..80b45685dcb 100644
--- a/src/interfaces/libpq++/pgconnection.cc
+++ b/src/interfaces/libpq++/pgconnection.cc
@@ -10,7 +10,7 @@
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.9 2000/04/22 22:39:15 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.10 2000/07/27 19:44:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -46,16 +46,32 @@ PgConnection::~PgConnection()
// Close the connection only if needed
// This feature will most probably be used by the derived classes that
// need not close the connection after they are destructed.
- if ( pgCloseConnection ) {
+ CloseConnection();
+}
+
+
+// PgConnection::CloseConnection()
+// close down the connection if there is one
+void PgConnection::CloseConnection()
+{
+ // if the connection is open, close it first
+ if ( pgCloseConnection ) {
if(pgResult) PQclear(pgResult);
+ pgResult=NULL;
if(pgConn) PQfinish(pgConn);
+ pgConn=NULL;
+ pgCloseConnection=0;
}
}
+
// PgConnection::connect
// establish a connection to a backend
ConnStatusType PgConnection::Connect(const char* conninfo)
{
+ // if the connection is open, close it first
+ CloseConnection();
+
// Connect to the database
pgConn = PQconnectdb(conninfo);
diff --git a/src/interfaces/libpq++/pgconnection.h b/src/interfaces/libpq++/pgconnection.h
index 0a19359a9f5..1e7ccbad61d 100644
--- a/src/interfaces/libpq++/pgconnection.h
+++ b/src/interfaces/libpq++/pgconnection.h
@@ -13,7 +13,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pgconnection.h,v 1.7 2000/04/22 22:39:15 tgl Exp $
+ * $Id: pgconnection.h,v 1.8 2000/07/27 19:44:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -81,6 +81,7 @@ public:
protected:
ConnStatusType Connect(const char* conninfo);
+ void CloseConnection();
string IntToString(int);
// Default constructor is only available to subclasses
PgConnection();