Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZJy7i-0005zj-W4 for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Jul 2015 06:12:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZJy7i-00060P-I8 for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Jul 2015 06:12:22 +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) (envelope-from ) id 1ZJy77-0005K6-26 for pgsql-bugs@postgresql.org; Tue, 28 Jul 2015 06:11:45 +0000 Received: from mail-pd0-x233.google.com ([2607:f8b0:400e:c02::233]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZJy73-00047S-St for pgsql-bugs@postgresql.org; Tue, 28 Jul 2015 06:11:44 +0000 Received: by pdjr16 with SMTP id r16so66111303pdj.3 for ; Mon, 27 Jul 2015 23:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=5rnZmp6qw/fnUsR8cBCepbakbbN6vLlpUhKG8GtNotQ=; b=0x5kKr9S4q2vipIjxD2Gp2J02Z816GEQYLxULynYbA/D84dOsyw9BagPdQfyksERsA q+EBTRC91quOdAM3ngj8Gf61zlB0SxsqS6dfS+ep5cUGS5mRGx9cNFbGvT0e0jnzqnD1 m3JTBtxW9ESal9pyV51V7lHsmr82U4NCAaP0Z6ItvE+MV48/tK9O9FHvleWEmS5s6VqO W7GyyyBvVbVjt6aKtMtJOAD3j3HdhBq1YMyfc9hcoECX5r9XkPQ67NjpGyc5aJagMLv9 UTNuNoKUnqU+QSwiBh+iiuITXVFOpY2H0zRN+VcgtZinzPrj2wlSt0nmd7OjQyv4Oy+f sPLQ== X-Received: by 10.70.55.229 with SMTP id v5mr76215765pdp.136.1438063899428; Mon, 27 Jul 2015 23:11:39 -0700 (PDT) Received: from [192.168.1.105] (dsl-hkibrasgw1-58c38f-82.dhcp.inet.fi. [88.195.143.82]) by smtp.gmail.com with ESMTPSA id uk6sm33052503pac.27.2015.07.27.23.11.37 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Jul 2015 23:11:38 -0700 (PDT) Message-ID: <55B71D16.3060600@iki.fi> Date: Tue, 28 Jul 2015 09:11:34 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-Version: 1.0 To: Michael Paquier CC: Andres Freund , PostgreSQL mailing lists Subject: Re: Memory leak in XLOG reader facility when decoding records (caused by WAL refactoring) References: <20150726153248.GF12755@awork2.anarazel.de> <55B66B3A.3070906@iki.fi> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.4 (--) 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 On 07/28/2015 02:54 AM, Michael Paquier wrote: > On Tue, Jul 28, 2015 at 2:32 AM, Heikki Linnakangas wrote: >> Thanks, committed. The leak was not actually in the "main_data" handling, as >> quoted in the above snippet, but in the per-block buffers. > > The patch pushed does not take care of the leak (tested on 3d5cb31c). > With the test script I sent upthread, I am still seeing it: > ==32015== 154 bytes in 1 blocks are definitely lost in loss record 103 of 155 > ==32015== at 0x6B1B: malloc (in > /usr/local/Cellar/valgrind/3.10.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so) > ==32015== by 0x10000DB2D: pg_malloc_internal (fe_memutils.c:30) > ==32015== by 0x10000DE79: palloc (fe_memutils.c:118) > ==32015== by 0x100005270: DecodeXLogRecord (xlogreader.c:1200) > ==32015== by 0x100003A79: XLogReadRecord (xlogreader.c:458) > ==32015== by 0x100002AF0: findLastCheckpoint (parsexlog.c:186) > ==32015== by 0x1000017E1: main (pg_rewind.c:257) > ==32015== > ==32015== 154 bytes in 1 blocks are definitely lost in loss record 104 of 155 > ==32015== at 0x6B1B: malloc (in > /usr/local/Cellar/valgrind/3.10.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so) > ==32015== by 0x10000DB2D: pg_malloc_internal (fe_memutils.c:30) > ==32015== by 0x10000DE79: palloc (fe_memutils.c:118) > ==32015== by 0x100005270: DecodeXLogRecord (xlogreader.c:1200) > ==32015== by 0x100003A79: XLogReadRecord (xlogreader.c:458) > ==32015== by 0x1000022E0: extractPageMap (parsexlog.c:78) > ==32015== by 0x10000187C: main (pg_rewind.c:280) > > The problem is that state->max_block_id gets reset to -1 each time a > new record is read via ResetDecoder. Hence if we decode a record that > has block data and then if a second record that does not contain block > data is decoded, we will leak if XLogReaderFree is called because no > attempts will be made to pfree what has been allocated. Per se the > patch attached. Ok, committed. I hope we got it right this time.. - Heikki -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs