Leak repairs

From: "Dave Page" <dpage(at)vale-housing(dot)co(dot)uk>
To: <pgsql-odbc(at)postgresql(dot)org>
Cc: "Anoop Kumar" <anoopk(at)pervasive-postgres(dot)com>
Subject: Leak repairs
Date: 2005-07-15 13:35:33
Message-ID: E7F85A1B5FF8D44C8A1AF6885BC9A0E4AC92A3@ratbert.vale-housing.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-odbc

Hi Anoop,

I've spend a while (too long really!) tracking down the memory leaks
we've been seeing in the libpq driver. The code below is enough to see
the problems I've observed using perfmon monitoring the process's
private bytes value.

The attached patch fixes 2 leaks, each of which noticably reduce the
angle of the perfmon trace, however it's not quite flat yet, and my eyes
have gone blurry from looking! It seems to be leaking about 1Kb/per
SQLExecute/SQLFreeStmt (it was 4Kb when I started). It also removes an
unnecessary call to PQgetisnull that I noticed.

I haven't applied any of this to CVS - I'll leave that to you if you're
happy with it.

#include <windows.h>
#include <sqlext.h>
#include <stdio.h>

int main(void)
{
HENV hEnv = NULL;
HDBC hDBC = NULL;
HSTMT hStmt = NULL;
UCHAR szDSN[SQL_MAX_DSN_LENGTH] = "psqlodbc-libpq";
UCHAR szUID[64] = "postgres";
UCHAR* szPasswd = NULL;
UCHAR szSqlStr[] = "SELECT 1";
RETCODE retcode;
long loop = 0;

SQLAllocEnv (&hEnv);
SQLAllocConnect (hEnv, &hDBC);
retcode = SQLConnect (hDBC, szDSN, SQL_NTS, szUID, SQL_NTS,
szPasswd, SQL_NTS);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
while(loop < 100000)
{
retcode = SQLAllocStmt (hDBC, &hStmt);
retcode = SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr));
retcode = SQLExecute (hStmt);
SQLFreeStmt (hStmt, SQL_DROP);
loop++;
}
SQLDisconnect (hDBC);
}

SQLFreeConnect (hDBC);
SQLFreeEnv (hEnv);

return 0;
}

Regards, Dave.

Attachment Content-Type Size
plumbing.diff application/octet-stream 1.3 KB

Browse pgsql-odbc by date

  From Date Subject
Next Message Greg Campbell 2005-07-15 13:36:58 Re: Has anyone accessed postgresql in linux from VB code
Previous Message Dave Page 2005-07-15 09:50:24 Re: Fix for the 'null value' bug