Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tCsg1-00EFhf-LP for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Nov 2024 03:43:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tCsfy-002jrV-J6 for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Nov 2024 03:43:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tCsfy-002jrN-8Q for pgsql-hackers@lists.postgresql.org; Mon, 18 Nov 2024 03:43:46 +0000 Received: from fhigh-a7-smtp.messagingengine.com ([103.168.172.158]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tCsfr-002Vkc-Ii for pgsql-hackers@postgresql.org; Mon, 18 Nov 2024 03:43:46 +0000 Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 921A8114015F; Sun, 17 Nov 2024 22:43:38 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Sun, 17 Nov 2024 22:43:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1731901418; x=1731987818; bh=mf3smBIVSN b+Mg3nkBI85Hm7VbVdfqXusQ5k8m/MwsA=; b=lO3Z4t/DqWfVRGllav45js1+PM 7H6D+dyLk7/4rb2zgIgk4DFfpeSoxNCI8uqy79cFEwxZAVyNPkz9gshW64ua424e qSJANj2A03D6Ze86EZoJphGAYezGYykBG5zXWOjCapcM1DctWbZL9DSLQxWu5Cso EuOGsPjpI7l6PbcXSGRJRdz0IzdRHpTNG8llGc2mH0QOTj3dPMC55EW/voEm1rNJ GBJ4kjZ3LAXFqiQTSACq8rBWjy+exrXEfJ1TpaTzditSh7WfBZuphXB4jbe5o3xq gwLCKI74DLyi7Jr3/xmmU4Cc/5r6ajMC5NlYqLc0xXPPHfTVzWWZuv0riYNg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1731901418; x=1731987818; bh=mf3smBIVSNb+Mg3nkBI85Hm7VbVdfqXusQ5 k8m/MwsA=; b=nbX6m0enSNK1EVC5HZiY8SYBXrG6BscLtoHu0BwnwQlO1RBryFs RS+o8JCfOUkNVGlln1pde0Y9igiK6bZ69p65myo56cyAfCZeBe/pGtqbf7Vwn9kc +nJDPopnlpa1L2iDYmFJt/aWHZs0DzWQk0dbUxMBvNb18GOl7pJRn5F6EDY5inup i2Rp4+D9AwxG4I0XXd+uatq4dVrF4jhZB6lf9VVHWmWetsJncJjtYm9UYgjAvufL 72669677O3QOAjp7oDObTsYh0sU5bWSeHmIYaaKQGFYX6s0RQ6wCIrqoxcBHPRKV 3moF5jVQA9is7mpAi+M6guHJarU9ZgoZARw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrvdelgdeifecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenfghrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffkfhgg tggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoe hmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeetleei fedufffhhfdtteelgeeggeffhfekueevteeigfduudevudetgfegiedvjeenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehp rghquhhivghrrdighiiipdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuth dprhgtphhtthhopehhohhuiihjrdhfnhhsthesfhhujhhithhsuhdrtghomhdprhgtphht thhopehmohgsihhlvgdrhigrnhhgsehouhhtlhhoohhkrdgtohhmpdhrtghpthhtohepph hgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 17 Nov 2024 22:43:36 -0500 (EST) Date: Mon, 18 Nov 2024 12:43:27 +0900 From: Michael Paquier To: "Zhijie Hou (Fujitsu)" Cc: by Yang , "pgsql-hackers@postgresql.org" Subject: Re: memory leak in pgoutput Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="RjN34q9EIQl7AEp9" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --RjN34q9EIQl7AEp9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 18, 2024 at 02:53:52AM +0000, Zhijie Hou (Fujitsu) wrote: > But I think there is an issue in the attached patch: >=20 > + FreeTupleDesc(entry->old_slot->tts_tupleDescriptor); > ExecDropSingleTupleTableSlot(entry->old_slot); >=20 > Here, after freeing the tupledesc, the ExecDropSingleTupleTableSlot will = still > access the freed tupledesc->tdrefcount which is an illegal memory access. >=20 > I think we can do something like below instead: >=20 > + TupleDesc desc =3D entry->old_slot->tts_tupleDescriptor; > + > + Assert(desc->tdrefcount =3D=3D -1); > + > ExecDropSingleTupleTableSlot(entry->old_slot); > + FreeTupleDesc(desc); Yep, obviously. I was first surprised that the DecrTupleDescRefCount() done in ExecDropSingleTupleTableSlot() would not be enough to free the TupleDesc. We do some allocations for dynamically-allocated resources like what pgoutput does in the SRF code, if I recall correctly, as these need are a problem across multiple calls and the query-level memory context would not do this cleanup.. -- Michael --RjN34q9EIQl7AEp9 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmc6t98ACgkQnvQgOdby QH0pyQ//e7Hyg78usE7U0faT49A7iZc1/4Abj17jnixffDRc/lTsgSPmnF6OrchS FQyqU+1MmTaE5XkJF51ote9IIik+wY+IKiOa30Fb1huMwwC/X25EkJF23EKbNDtb Lc2dMTwdqdId9dtkzXZPXHIFIWdzSbNEknItNFRa5cLwXHdwWVpWOy4P0Mr/aa6x CQogaNiAs/WyY1LPI30h5rNE8f9W3KHSSs4S6szxjmfe0kzYm1/wAVztY5jLKaCz K23kbJgw8RNwCeBy6TeglXUo9k9UVJJfYu9wSw19y04j9rcosnF/5YZNCUSpIC2e i31EAeVlozK9spOalbN2oM697RHXyE6G2MLLeUQQbQyvgs7yUKX4mlQE4mNfhZuv sbb3GXIIncsflP2NiVz/78btfhTXeGjoteiTqOWT1Q9NrQpHXqGcoueNaTXBvWhg JF455BzZ44+iAKNnmmw4QP+jTPu9qRJKKU3hyfLY5eM2jZDMOoHBzff4y0c0U9GL HHTH4A9wNE3j9GSzo2hb/pW4yRKhSUGuF59z6ujvgwUt1uLwxs78g3KLWMPeMNzU 0p30a29h5BCTP1xXdMEAwojuVSmG0yO926NYIyyFtjhIyk8oeSx83JdEKb66CZ5q +12M0ypicWDGYkhu+ikEylIEobDmRPjBwVYhSTrTEy/ebzmBFz4= =qdQT -----END PGP SIGNATURE----- --RjN34q9EIQl7AEp9--