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 1f8BAf-0006S7-M4 for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Apr 2018 20:56:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f8BAd-0004pf-S5 for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Apr 2018 20:56:15 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f8BAd-0004pW-I7 for pgsql-bugs@lists.postgresql.org; Mon, 16 Apr 2018 20:56:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f8BAb-0004gw-2l for pgsql-bugs@lists.postgresql.org; Mon, 16 Apr 2018 20:56:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w3GKu5vB029480; Mon, 16 Apr 2018 16:56:05 -0400 From: Tom Lane To: Peter Geoghegan cc: Alvaro Herrera , Andres Freund , "Vitaly V. Voronov" , PostgreSQL mailing lists Subject: Re: BUG #15144: *** glibc detected *** postgres: postgres smsconsole [local] SELECT: double free or corruption (!pre In-reply-to: References: <20180416174817.3krcrdtfkiwkhj4s@alvherre.pgsql> Comments: In-reply-to Peter Geoghegan message dated "Mon, 16 Apr 2018 11:03:04 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29478.1523912165.1@sss.pgh.pa.us> Date: Mon, 16 Apr 2018 16:56:05 -0400 Message-ID: <29479.1523912165@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Geoghegan writes: > Offhand, I find it more likely > that some executor slot that imagines that it owns the tuple frees the > tuple once, which is followed by a call to tuplestore_end() that frees > the same tuple a second time (a double-free). As I mentioned, we've > seen several bugs of that general variety in both tuplestore and > tuplesort in the past. Some of these have been very subtle. I see that in 9.6, nodeFunctionScan thinks it should do ExecClearTuple on the func_slot that it's received from tuplestore_gettupleslot, which it calls with copy = false, meaning that ExecClearTuple might be deleting a tuple returned by tuplestore_gettuple. I wonder if this is the same kind of issue we fixed in 90decdba3, only for tuplestore rather than tuplesort. tuplestore_gettuple doesn't return should_free = true unless the tuplestore spilled to disk, so the sort of issue I'm imagining would only arise for function results large enough to cause a spill. BTW, I notice that in this situation, readtup_heap seems to be palloc'ing in the caller's context, but it counts the memory as if it were in the tuplestore's context. Somebody's confused there. regards, tom lane