Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cd26d-0002de-Iu for pgsql-bugs@arkaria.postgresql.org; Sun, 12 Feb 2017 21:54:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cd26d-0007fD-1Y for pgsql-bugs@arkaria.postgresql.org; Sun, 12 Feb 2017 21:54:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cd25y-0006vq-4A for pgsql-bugs@postgresql.org; Sun, 12 Feb 2017 21:54:10 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cd25p-000068-Fm for pgsql-bugs@postgresql.org; Sun, 12 Feb 2017 21:54:07 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id E3AB4206E5; Sun, 12 Feb 2017 16:53:58 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Sun, 12 Feb 2017 16:53:58 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=LvOhaDn2pVOGXq9LNwSpzI57Yvg=; b=P1ost8u06QQNfGcAl5UB z1Dvfl3OTBpevKGBLFEfQJ3oGCQsjhZjyX7L+Su2jsXTNWlgepqYcdoW8BN4LrPA WrOCIIzLJMGyJYbVOBVmS5UBip82sEH5JE86ITtgTweXK5qK8W0PLG1ccVtHbAI7 L0AA4Y0mwsGU/51Onsa5970= X-ME-Sender: X-Sasl-enc: C8X7hEBn0mhk5TWTd9Ww3TCYw9aDjCwVBNEFZS2XWpMw 1486936438 Received: from intern.anarazel.de (unknown [199.87.86.247]) by mail.messagingengine.com (Postfix) with ESMTPA id 7F3892459C; Sun, 12 Feb 2017 16:53:58 -0500 (EST) Date: Sun, 12 Feb 2017 13:53:57 -0800 From: Andres Freund To: Michael Cress Cc: "pgsql-bugs@postgresql.org" Subject: Re: (Benign ?) Libpq memory leak Message-ID: <20170212215357.ej6mhm3ajxmoiz3t@alap3.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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: ??? > > ==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: ??? > 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