Re: BUG #6234: Memory leak from PQexec

Lists: pgsql-bugs
From: "Vikas Mehta" <mehta(at)roguewave(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #6234: Memory leak from PQexec
Date: 2011-09-28 22:22:12
Message-ID: 201109282222.p8SMMCsH033290@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 6234
Logged by: Vikas Mehta
Email address: mehta(at)roguewave(dot)com
PostgreSQL version: 8.4.8
Operating system: Windows
Description: Memory leak from PQexec
Details:

Purify shows 448 bytes of memory leaks with PQexec:

[W] Summary of all memory leaks... {448 bytes, 11 blocks}
[W] MLK: Memory leak of 128 bytes from 1 block allocated in
ERR_load_SSL_strings [SSLEAY32.DLL]
[W] MLK: Memory leak of 128 bytes from 1 block allocated in
PQrequestCancel [LIBPQ.DLL]
[W] MLK: Memory leak of 128 bytes from 1 block allocated in
ENGINE_load_ubsec [LIBEAY32.DLL]
[W] MLK: Memory leak of 64 bytes from 8 blocks allocated in
add_error_table [COMERR32.DLL]

Test case:
==========

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <libpq-fe.h>

void createTestTable(PGconn* dbc)
{
PGresult *res;

printf("\n\nCreating Test Table.....\n");

res = PQexec(dbc, "create table mytable (col1 int)");
if (PQresultStatus(res) == PGRES_NONFATAL_ERROR || PQresultStatus(res)
== PGRES_FATAL_ERROR) {
printf("!!!!! Failed to create test table.\n");
}
PQclear(res);
}

void dropTestTable(PGconn* dbc)
{
PGresult *res;

printf("\n\nDropping Test Table.....\n");

res = PQexec(dbc, "drop table mytable");
if (PQresultStatus(res) == PGRES_NONFATAL_ERROR || PQresultStatus(res)
== PGRES_FATAL_ERROR) {
printf("!!!!! Failed to drop test table.\n");
}
PQclear(res);
}

int main()
{
PGconn *dbc;

dbc = PQconnectdb("host = magma.cvo.roguewave.com user = username
password = pwd dbname = db");

if(dbc == 0 || PQstatus(dbc) == CONNECTION_BAD) {
printf("!!!!! Failed to establish connection.\n");
}

createTestTable(dbc);

dropTestTable(dbc);

PQfinish(dbc);

return 0;
}


From: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
To: Vikas Mehta <mehta(at)roguewave(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #6234: Memory leak from PQexec
Date: 2011-09-30 06:01:49
Message-ID: 4E855B4D.5080700@ringerc.id.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On 29/09/2011 6:22 AM, Vikas Mehta wrote:
> The following bug has been logged online:
>
> Bug reference: 6234
> Logged by: Vikas Mehta
> Email address: mehta(at)roguewave(dot)com
> PostgreSQL version: 8.4.8
> Operating system: Windows
> Description: Memory leak from PQexec
> Details:
>
> Purify shows 448 bytes of memory leaks with PQexec:
>
> [W] Summary of all memory leaks... {448 bytes, 11 blocks}
> [W] MLK: Memory leak of 128 bytes from 1 block allocated in
> ERR_load_SSL_strings [SSLEAY32.DLL]
>
It's not a leak, and it's not a bug. Please search the pgsql-general
archives for "valgrind" or "SSL_config".

--
Craig Ringer


From: Vikas Mehta <Vikas(dot)Mehta(at)roguewave(dot)com>
To: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #6234: Memory leak from PQexec
Date: 2011-10-03 18:13:27
Message-ID: 53D52D02E87FA04A948D9A74A7AE617C0B47D8FD54@Eagle.Blue.Roguewave.Com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Thanks. I found posts on SSL leak reported by purify. However, I couldn't find any information on the memory leak from PQrequestCancel. Is it a known issue?

-----Original Message-----
From: Craig Ringer [mailto:ringerc(at)ringerc(dot)id(dot)au]
Sent: Friday, September 30, 2011 12:02 AM
To: Vikas Mehta
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: [BUGS] BUG #6234: Memory leak from PQexec

On 29/09/2011 6:22 AM, Vikas Mehta wrote:
> The following bug has been logged online:
>
> Bug reference: 6234
> Logged by: Vikas Mehta
> Email address: mehta(at)roguewave(dot)com
> PostgreSQL version: 8.4.8
> Operating system: Windows
> Description: Memory leak from PQexec
> Details:
>
> Purify shows 448 bytes of memory leaks with PQexec:
>
> [W] Summary of all memory leaks... {448 bytes, 11 blocks}
> [W] MLK: Memory leak of 128 bytes from 1 block allocated in
> ERR_load_SSL_strings [SSLEAY32.DLL]
>
It's not a leak, and it's not a bug. Please search the pgsql-general archives for "valgrind" or "SSL_config".

--
Craig Ringer


From: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
To: PostgreSQL bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #6234: Memory leak from PQexec
Date: 2011-10-04 00:22:24
Message-ID: CAD2md3Gb+gXTYR5fMk1m9OqWYUSwLu7TGxiYwK7gUnC9P+sw7A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On Oct 4, 2011 2:14 AM, "Vikas Mehta" <Vikas(dot)Mehta(at)roguewave(dot)com> wrote:
>
> Thanks. I found posts on SSL leak reported by purify. However, I couldn't
find any information on the memory leak from PQrequestCancel. Is it a known
issue?

It's essentially the same issue. OpenSSL loads some strings, config
variables etc on demand/first use and doesn't bother to free them. This is
fine because they are only ever loaded once, so there is no continuous
growth with repeated invocations and no leak. Freeing them before program
exit is hard because of ordering issues, so they just let the OS clean it up
with the rest of the process's memory. That's perfectly correct.

If repeat invocations of your problem code within one program session cause
the heap to grow and the reported leak to get bigger / appear more times,
THEN it is a real leak and a real bug.

>
> -----Original Message-----
> From: Craig Ringer [mailto:ringerc(at)ringerc(dot)id(dot)au]
> Sent: Friday, September 30, 2011 12:02 AM
> To: Vikas Mehta
> Cc: pgsql-bugs(at)postgresql(dot)org
> Subject: Re: [BUGS] BUG #6234: Memory leak from PQexec
>
> On 29/09/2011 6:22 AM, Vikas Mehta wrote:
> > The following bug has been logged online:
> >
> > Bug reference: 6234
> > Logged by: Vikas Mehta
> > Email address: mehta(at)roguewave(dot)com
> > PostgreSQL version: 8.4.8
> > Operating system: Windows
> > Description: Memory leak from PQexec
> > Details:
> >
> > Purify shows 448 bytes of memory leaks with PQexec:
> >
> > [W] Summary of all memory leaks... {448 bytes, 11 blocks}
> > [W] MLK: Memory leak of 128 bytes from 1 block allocated in
> > ERR_load_SSL_strings [SSLEAY32.DLL]
> >
> It's not a leak, and it's not a bug. Please search the pgsql-general
archives for "valgrind" or "SSL_config".
>
> --
> Craig Ringer