pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedlibpq leaks memory for SSL connections
3+ messages / 2 participants
[nested] [flat]
* libpq leaks memory for SSL connections
@ 2021-10-01 12:49 Timo Sirainen <timo@sirainen.com>
0 siblings, 1 reply; 3+ messages in thread
From: Timo Sirainen @ 2021-10-01 12:49 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org
I noticed with valgrind how libpq is leaking memory:
at 0x483577F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x5F645C8: CRYPTO_zalloc (in /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1)
by 0x5E94EEF: BIO_meth_new (in /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1)
by 0x65181EB: ??? (in /usr/lib/x86_64-linux-gnu/libpq.so.5.11)
by 0x651950C: ??? (in /usr/lib/x86_64-linux-gnu/libpq.so.5.11)
by 0x650140F: PQconnectPoll (in /usr/lib/x86_64-linux-gnu/libpq.so.5.11)
Debian doesn't have debuginfo packages for libpq, but looking at the code I think it's pretty clear where the bug is:
my_SSL_set_fd() calls my_BIO_s_socket() which allocates memory with BIO_meth_new(), but nothing ever frees it. Note that OpenSSL's BIO_s_socket() returns a const pointer to statically allocated memory.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: libpq leaks memory for SSL connections
@ 2021-10-01 19:46 Tom Lane <tgl@sss.pgh.pa.us>
parent: Timo Sirainen <timo@sirainen.com>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2021-10-01 19:46 UTC (permalink / raw)
To: Timo Sirainen <timo@sirainen.com>; +Cc: pgsql-bugs@lists.postgresql.org
Timo Sirainen <timo@sirainen.com> writes:
> I noticed with valgrind how libpq is leaking memory:
> at 0x483577F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
> by 0x5F645C8: CRYPTO_zalloc (in /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1)
> by 0x5E94EEF: BIO_meth_new (in /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1)
> by 0x65181EB: ??? (in /usr/lib/x86_64-linux-gnu/libpq.so.5.11)
> by 0x651950C: ??? (in /usr/lib/x86_64-linux-gnu/libpq.so.5.11)
> by 0x650140F: PQconnectPoll (in /usr/lib/x86_64-linux-gnu/libpq.so.5.11)
I see no leak here. The struct is allocated once and kept for possible
re-use by future connections. valgrind concurs, saying it's "still
reachable".
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: libpq leaks memory for SSL connections
@ 2021-10-01 20:06 Timo Sirainen <timo@sirainen.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Timo Sirainen @ 2021-10-01 20:06 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs@lists.postgresql.org
On 1. Oct 2021, at 21.46, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Timo Sirainen <timo@sirainen.com> writes:
>> I noticed with valgrind how libpq is leaking memory:
>> at 0x483577F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
>> by 0x5F645C8: CRYPTO_zalloc (in /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1)
>> by 0x5E94EEF: BIO_meth_new (in /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1)
>> by 0x65181EB: ??? (in /usr/lib/x86_64-linux-gnu/libpq.so.5.11)
>> by 0x651950C: ??? (in /usr/lib/x86_64-linux-gnu/libpq.so.5.11)
>> by 0x650140F: PQconnectPoll (in /usr/lib/x86_64-linux-gnu/libpq.so.5.11)
>
> I see no leak here. The struct is allocated once and kept for possible
> re-use by future connections. valgrind concurs, saying it's "still
> reachable".
Oh, right, somehow I missed it didn't allocate new memory every time. And for some reason valgrind tells me it is "definitely lost". It would be nice if there was some PQglobalDeinit() function that could be called to free it to avoid having to add valgrind suppression, but I guess that's more of a feature request.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2021-10-01 20:06 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 12:49 libpq leaks memory for SSL connections Timo Sirainen <timo@sirainen.com>
2021-10-01 19:46 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-10-01 20:06 ` Timo Sirainen <timo@sirainen.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox