Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f8HbY-0003Rg-LW for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Apr 2018 03:48:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f8HbW-0002pt-JH for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Apr 2018 03:48:26 +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.89) (envelope-from ) id 1f8HbW-0002pk-Cr for pgsql-bugs@lists.postgresql.org; Tue, 17 Apr 2018 03:48:26 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f8HbT-0000A1-3G for pgsql-bugs@lists.postgresql.org; Tue, 17 Apr 2018 03:48:25 +0000 Received: from [192.168.127.1] (port=56269 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1f8HbM-000MvW-Ag; Tue, 17 Apr 2018 03:48:16 +0000 Received: from [127.0.0.1] (port=14438 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1f8HbL-000C6L-Kv; Tue, 17 Apr 2018 03:48:15 +0000 From: Andrew Gierth To: Vitaly V. Voronov Cc: Tom Lane , Alvaro Herrera , Andres Freund , PostgreSQL mailing lists , Peter Geoghegan Subject: Re: BUG #15144: *** glibc detected *** postgres: postgres smsconsole [local] SELECT: double free or corruption (!pre In-Reply-To: <1935021523893352@web12o.yandex.ru> (Vitaly V. Voronov's message of "Mon, 16 Apr 2018 18:42:32 +0300") Message-ID: <87y3hmee19.fsf@news-spur.riddles.org.uk> References: <152296798225.31227.6026116154621550125@wrigleys.postgresql.org> <3343581523000521@web56o.yandex.ru> <1935021523893352@web12o.yandex.ru> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Tue, 17 Apr 2018 04:48:14 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Vitaly" == Vitaly V Voronov writes: Vitaly> #4 0x0000003d22278c80 in _int_free () from /lib64/libc.so.6 Vitaly> No symbol table info available. Vitaly> #5 0x0000000000808887 in tuplestore_end (state=0x1794898) at tuplestore.c:455 Vitaly> i = So I may be off base here but... Line 455 isn't anything to do with tuples; it's the BufFileClose() line. Furthermore, there's no stack frame between the free() and the tuplestore_end. From looking at optimized builds, this suggests that free() has been reached via tail calls, and the only way I see that happening is when pfree() is being called on a large allocation (one large enough to be its own chunk), which shouldn't happen for tuples in this example. (It can happen for the memtuples array itself.) BufFile is a struct with a big buffer in it, though, so it'll be a large allocation, hence the pfree() at the end of BufFileClose will end up in free() via tail calls. Of course the weak point in this theory is that there seems to be no reason at all why BufFileClose could possibly get called twice ... the only other theory would be that something has somehow reset the memory context _before_ we got here. -- Andrew (irc:RhodiumToad)