libpq leaks memory for SSL connections

From: Timo Sirainen <timo(at)sirainen(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: libpq leaks memory for SSL connections
Date: 2021-10-01 12:49:38
Message-ID: CE981CB2-8907-4530-9886-24A54C9056B9@sirainen.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2021-10-01 13:20:01 BUG #17210: Postgres Let'sEncrypt root certificate is expired and breaks installation of postgres-client
Previous Message PG Bug reporting form 2021-10-01 12:16:55 BUG #17209: The latest pgdg-redhat-repo-latest.noarch has incorrect path for pgdg14