Re: libpq3 + ssl memory leak - Mailing list pgsql-bugs

From Neil Conway
Subject Re: libpq3 + ssl memory leak
Date
Msg-id 877k130z42.fsf@mailbox.samurai.com
Whole thread Raw
In response to Re: libpq3 + ssl memory leak  (Neil Conway <neilc@samurai.com>)
Responses Re: libpq3 + ssl memory leak  (Neil Conway <neilc@samurai.com>)
List pgsql-bugs
Neil Conway <neilc@samurai.com> writes:
> I can verify this locally. Unfortunately, my copy of valgrind doesn't
> seem to be picking up the debugging symbols for OpenSSL

Ok, some progress. I installed a development snapshot of OpenSSL, and
confirmed that the problem still occurs there. The full valgrind leak
trace call stack is:

==14598== 8316 bytes in 99 blocks are definitely lost in loss record 5 of 7
==14598==    at 0x4002CA5D: malloc (vg_replace_malloc.c:153)
==14598==    by 0x4040340C: default_malloc_ex (mem.c:79)
==14598==    by 0x40403A93: CRYPTO_malloc (mem.c:304)
==14598==    by 0x4048F8A4: asn1_item_ex_combine_new (tasn_new.c:171)
==14598==    by 0x4048F5E4: ASN1_item_ex_new (tasn_new.c:83)
==14598==    by 0x40491A91: ASN1_item_ex_d2i (tasn_dec.c:318)
==14598==    by 0x40491423: ASN1_item_d2i (tasn_dec.c:115)
==14598==    by 0x404897DD: d2i_X509 (x_x509.c:125)
==14598==    by 0x403AAF22: ssl3_get_server_certificate (s3_clnt.c:837)
==14598==    by 0x403A9E87: ssl3_connect (s3_clnt.c:295)
==14598==    by 0x403B89AD: SSL_connect (ssl_lib.c:829)
==14598==    by 0x4025C5FA: open_client_SSL (fe-secure.c:898)
==14598==    by 0x4025B62B: pqsecure_open_client (fe-secure.c:253)
==14598==    by 0x4024D496: PQconnectPoll (fe-connect.c:1518)
==14598==    by 0x4024CBB0: connectDBComplete (fe-connect.c:1060)
==14598==    by 0x4024BB8D: PQconnectdb (fe-connect.c:248)
==14598==    by 0x804860E: main (leak.c:11)
==14598==    by 0x40279DA5: __libc_start_main (libc-start.c:242)
==14598==    by 0x8048540: ??? (start.S:102)

(The line numbers are against the snapshot I'm using, which you can
get from ftp://ftp.openssl.org/snapshot/openssl-SNAP-20031211.tar.gz)

A cursory look at the libpq SSL code doesn't reveal anything obvious
that we're doing wrong (e.g. SSL_new() calls seem to be matched up
with SSL_free() calls AFAICS). The problem doesn't seem to occur if I
link against 7.3's libpq.so, so this does seem to be a libpq bug (and
not an OpenSSL leak).

BTW Sean, do you have any insight into the problem?

I'll continue working on it and let the list know if I learn anything
new.

-Neil

pgsql-bugs by date:

Previous
From: Seum-Lim Gan
Date:
Subject: Re: dyntest.pgc not working in 7.4 ?
Next
From: Kris Jurka
Date:
Subject: Re: BUG #1005: JDBC cancelRowUpdates() sets column values to