From: Andres Freund <andres@anarazel.de>
To: Michael Cress <michael.cress@cress.us>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: (Benign ?) Libpq memory leak
Date: Sun, 12 Feb 2017 13:53:57 -0800
Message-ID: <20170212215357.ej6mhm3ajxmoiz3t@alap3.anarazel.de> (raw)
In-Reply-To: <SN1PR19MB0654F47A94C587C62C706C179B460@SN1PR19MB0654.namprd19.prod.outlook.com>
References: <SN1PR19MB0654F47A94C587C62C706C179B460@SN1PR19MB0654.namprd19.prod.outlook.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Hi,m
On 2017-02-12 21:40:11 +0000, Michael Cress wrote:
> I have noticed a memory leak in libpq. Running the following code from the context of a worker thread leaks 1024 bytes:
>
> const char conninfo[] = "dbname=testdb host=localhost user=testaccount password=password";
> PGconn *conn;
> PGresult *res;
> int nFields, i, j;
>
> printf("Opening connection to database\n");
> conn = PQconnectdb(conninfo);
>
> /* PQ statements used to be here but were removed when the leak was noticed. They executed fine and did not contribute to the leak. */
>
> printf("Closing connection to database\n");
> PQfinish(conn);
> ==19194== HEAP SUMMARY:
> ==19194== in use at exit: 5,324 bytes in 25 blocks
> ==19194== total heap usage: 33,714 allocs, 33,689 frees, 5,311,760 bytes allocated
> ==19194==
> ==19194== 40 bytes in 1 blocks are definitely lost in loss record 3 of 9
> ==19194== at 0x402E23C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
> ==19194== by 0x7DE3E42: ???
> ==19194== by 0x7DE4F5E: ???
> ==19194== by 0x7DDF577: ???
> ==19194== by 0x7DD0698: ???
> ==19194== by 0x7DD0EAA: ???
> ==19194== by 0x7DD184E: ???
> ==19194== by 0x42D6C18: ???
> <Redacted application call stack specific to application>
> ==19194==
> ==19194== 984 bytes in 1 blocks are definitely lost in loss record 8 of 9
> ==19194== at 0x402E23C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
> ==19194== by 0x7DE4BC3: ???
> ==19194== by 0x7DDF557: ???
> ==19194== by 0x7DD067E: ???
> ==19194== by 0x7DD0EAA: ???
> ==19194== by 0x7DD184E: ???
> ==19194== by 0x42D6C18: ???
> <Redacted application call stack specific to application>
Without libpq call-stack it's hard to make useful comments here. Could
you recompile with debugging symbols / install debugging symbols?
> The system environment is x86 running an up-to-date Ubuntu 16.10. The version of Postgresql installed is “9.5.5”. I have not performed any tests on other environments. This test was conducted against a development database containing data as well as a test database containing no data.
IIRC recent ubuntu version provide dbgsym packages in a separate
repository that you need to enable.
Greetings,
Andres Freund
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: andres@anarazel.de, michael.cress@cress.us
Subject: Re: (Benign ?) Libpq memory leak
In-Reply-To: <20170212215357.ej6mhm3ajxmoiz3t@alap3.anarazel.de>
References: <SN1PR19MB0654F47A94C587C62C706C179B460@SN1PR19MB0654.namprd19.prod.outlook.com> <20170212215357.ej6mhm3ajxmoiz3t@alap3.anarazel.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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