From bcbc9bb3d08ae6e1d3fef780da820f0bb2735ecd Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Tue, 12 Jun 2007 14:24:56 +0000 Subject: [PATCH] Fix a bug which doesn't free connection list properly. --- connection.c | 9 +++------ environ.c | 36 ++++++++++++++++++++++++++---------- version.h | 2 +- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/connection.c b/connection.c index 68d61e0..65b38c0 100644 --- a/connection.c +++ b/connection.c @@ -1264,7 +1264,7 @@ static char CC_initial_log(ConnectionClass *self, const char *func) snprintf(vermsg, sizeof(vermsg), "Driver Version='%s,%s'" #ifdef WIN32 - " linking" + " linking %d" #ifdef _MT #ifdef _DLL " dynamic" @@ -1275,16 +1275,12 @@ static char CC_initial_log(ConnectionClass *self, const char *func) #else " Singlethread" #endif /* _MT */ -#ifdef NOT_USED #ifdef _DEBUG " Debug" -#else - " Release" #endif /* DEBUG */ -#endif /* NOT_USED */ " library" #endif /* WIN32 */ - "\n", POSTGRESDRIVERVERSION, PG_BUILD_VERSION); + "\n", POSTGRESDRIVERVERSION, PG_BUILD_VERSION, _MSC_VER); qlog(vermsg); mylog(vermsg); qlog("Global Options: fetch=%d, socket=%d, unknown_sizes=%d, max_varchar_size=%d, max_longvarchar_size=%d\n", @@ -3468,6 +3464,7 @@ cleanup1: inolog("socket=%d\n", socket); sock->socket = socket; sock->ssl = PQgetssl(pqconn); +inolog("ssl=%p\n", sock->ssl); if (TRUE) { int pversion; diff --git a/environ.c b/environ.c index f70e243..e1d8893 100644 --- a/environ.c +++ b/environ.c @@ -514,20 +514,25 @@ EN_Constructor(void) #ifndef _WSASTARTUP_IN_DLLMAIN_ WORD wVersionRequested; WSADATA wsaData; + const int major = 1, minor = 1; /* Load the WinSock Library */ - wVersionRequested = MAKEWORD(1, 1); + wVersionRequested = MAKEWORD(major, minor); if (WSAStartup(wVersionRequested, &wsaData)) + { + mylog("%s: WSAStartup error\n", func); return rv; + } /* Verify that this is the minimum version of WinSock */ - if (LOBYTE(wsaData.wVersion) != 1 || - HIBYTE(wsaData.wVersion) != 1) + if (LOBYTE(wsaData.wVersion) != major || + HIBYTE(wsaData.wVersion) != minor) { - goto cleanup; + mylog("%s: WSAStartup version=(%d,%d)\n", func, + LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion)); } #endif /* _WSASTARTUP_IN_DLLMAIN_ */ -#endif +#endif /* WIN32 */ rv = (EnvironmentClass *) malloc(sizeof(EnvironmentClass)); cleanup: @@ -541,9 +546,12 @@ cleanup: #ifdef WIN32 #ifndef _WSASTARTUP_IN_DLLMAIN_ else + { + mylog("%s: malloc error\n", func); WSACleanup(); + } #endif /* _WSASTARTUP_IN_DLLMAIN_ */ -#endif +#endif /* WIN32 */ return rv; } @@ -552,7 +560,7 @@ cleanup: char EN_Destructor(EnvironmentClass *self) { - int lf; + int lf, nullcnt; char rv = 1; mylog("in EN_Destructor, self=%p\n", self); @@ -565,18 +573,26 @@ EN_Destructor(EnvironmentClass *self) */ /* Free any connections belonging to this environment */ - for (lf = 0; lf < conns_count; lf++) + for (lf = 0, nullcnt = 0; lf < conns_count; lf++) { - if (conns[lf] && conns[lf]->henv == self) + if (NULL == conns[lf]) + nullcnt++; + else if (conns[lf]->henv == self) { if (CC_Destructor(conns[lf])) conns[lf] = NULL; else rv = 0; + nullcnt++; } } - if (conns) + if (conns && nullcnt >= conns_count) + { + mylog("clearing conns count=%d\n", conns_count); free(conns); + conns = NULL; + conns_count = 0; + } DELETE_ENV_CS(self); free(self); diff --git a/version.h b/version.h index cd6eb4e..618744f 100644 --- a/version.h +++ b/version.h @@ -12,6 +12,6 @@ #define POSTGRESDRIVERVERSION "08.02.0402" #define POSTGRES_RESOURCE_VERSION "08.02.0402\0" #define PG_DRVFILE_VERSION 8,2,04,02 -#define PG_BUILD_VERSION "200706040002" +#define PG_BUILD_VERSION "200706120001" #endif -- 2.39.5