Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3b4400

Browse files
committed
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 postgresql6.5.3 and 7.0.2. Can someone please review it and apply it to thesource tree?Sometimes when the postgres connection dies it is necessary toattempt to reconnect. Calling the pgconnection::Connect method in aderived class leaks memory because it does not clear the currentconnection (if there is one). These patches ensures that any openconnections are closed before attempting to open a new one.-Michael Richards
1 parent1ee0d4a commite3b4400

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

‎src/interfaces/libpq++/pgconnection.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 1994, Regents of the University of California
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.9 2000/04/22 22:39:15 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.10 2000/07/27 19:44:01 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -46,16 +46,32 @@ PgConnection::~PgConnection()
4646
// Close the connection only if needed
4747
// This feature will most probably be used by the derived classes that
4848
// need not close the connection after they are destructed.
49-
if ( pgCloseConnection ) {
49+
CloseConnection();
50+
}
51+
52+
53+
// PgConnection::CloseConnection()
54+
// close down the connection if there is one
55+
voidPgConnection::CloseConnection()
56+
{
57+
// if the connection is open, close it first
58+
if ( pgCloseConnection ) {
5059
if(pgResult)PQclear(pgResult);
60+
pgResult=NULL;
5161
if(pgConn)PQfinish(pgConn);
62+
pgConn=NULL;
63+
pgCloseConnection=0;
5264
}
5365
}
5466

67+
5568
// PgConnection::connect
5669
// establish a connection to a backend
5770
ConnStatusTypePgConnection::Connect(constchar* conninfo)
5871
{
72+
// if the connection is open, close it first
73+
CloseConnection();
74+
5975
// Connect to the database
6076
pgConn =PQconnectdb(conninfo);
6177

‎src/interfaces/libpq++/pgconnection.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
16-
* $Id: pgconnection.h,v 1.7 2000/04/22 22:39:15 tgl Exp $
16+
* $Id: pgconnection.h,v 1.8 2000/07/27 19:44:01 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -81,6 +81,7 @@ class PgConnection {
8181

8282
protected:
8383
ConnStatusTypeConnect(constchar* conninfo);
84+
voidCloseConnection();
8485
stringIntToString(int);
8586
// Default constructor is only available to subclasses
8687
PgConnection();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp