Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXwJo-00056b-U2 for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2019 23:57:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iXwJm-0003G4-Ce for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2019 23:56:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXwJl-0003Fx-Qx for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2019 23:56:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iXwJe-0000Jj-V4 for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2019 23:56:56 +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 xALNulCP014167; Thu, 21 Nov 2019 18:56:48 -0500 From: Tom Lane To: Tomas Vondra cc: =?utf-8?Q?Ond=C5=99ej?= Jirman , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16129: Segfault in tts_virtual_materialize in logical replication worker In-reply-to: <20191121234701.2wtyc77zd5ux3myf@development> References: <20191121150716.szxqukxrtpjpckm3@core.my.home> <20191121152732.hu6y4wzw7nkxpsvk@development> <20191121155707.pqkgjphh65o5fapz@core.my.home> <20191121161502.xfiy65i3cm6adscr@core.my.home> <20191121165752.dffge6bh756xlfdg@development> <20191121173555.midj6vp4dmiiqs24@core.my.home> <20191121185844.6qsqhwzzuhu3fpsg@core.my.home> <20191121214115.3tgefmvkmrzaim74@development> <20191121220854.ebdzjtloel56sfwu@development> <13122.1574375845@sss.pgh.pa.us> <20191121234701.2wtyc77zd5ux3myf@development> Comments: In-reply-to Tomas Vondra message dated "Fri, 22 Nov 2019 00:47:01 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14165.1574380607.1@sss.pgh.pa.us> Date: Thu, 21 Nov 2019 18:56:47 -0500 Message-ID: <14166.1574380607@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tomas Vondra writes: > On Thu, Nov 21, 2019 at 05:37:25PM -0500, Tom Lane wrote: > I don't think that's quite true. After the ExecCopySlot call, the > pass-by-ref Datums in remoteslot will point to a tuple attached to > localslot. But it does not pass the tuple 'ownership' to the remoteslot, > i.e. the flag TTS_FLAG_SHOULDFREE won't be set, i.e. the tuple won't be > freed. Nope: static void tts_heap_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot) { HeapTuple tuple; MemoryContext oldcontext; oldcontext = MemoryContextSwitchTo(dstslot->tts_mcxt); tuple = ExecCopySlotHeapTuple(srcslot); MemoryContextSwitchTo(oldcontext); ExecStoreHeapTuple(tuple, dstslot, true); } "remoteslot" will contain its very own copy of the data, which is then summarily freed by ExecClearSlot. >> I imagine the only reason this code has gotten past the valgrind >> animals is that we're not testing cases where non-replaced columns >> in the subscriber table are of pass-by-ref types. > I haven't checked, but I'd imagine we actually do such tests. I've > however tried to reproduce this, unsuccessfully. I did check, and we don't. See patch. It's possible that the OP is seeing some different problem, but I can definitely demonstrate that there is a problem that this change fixes. regards, tom lane