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 1tHIqF-005ncE-RQ for pgsql-hackers@arkaria.postgresql.org; Sat, 30 Nov 2024 08:28:39 +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 1tHIqC-00EqTY-SG for pgsql-hackers@arkaria.postgresql.org; Sat, 30 Nov 2024 08:28:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tHIqC-00EqTO-1t for pgsql-hackers@lists.postgresql.org; Sat, 30 Nov 2024 08:28:37 +0000 Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tHIqA-000IYc-KG for pgsql-hackers@lists.postgresql.org; Sat, 30 Nov 2024 08:28:36 +0000 Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 900A911400E2; Sat, 30 Nov 2024 03:28:33 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Sat, 30 Nov 2024 03:28:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1732955313; x=1733041713; bh=7 ngnEvuWEtPPXR3UpsC1f9FBWWwOORHDulENbEHXgeY=; b=KpfNN4bzzyBxYZ5WB p/Ftxq/YDXPscUA3VJ9LrXBrID5ka3xrz317u3SmzA41hF2SHJosPhLyvop6tBLj DCJr+Gt7U0dOLbzsFT070v7nl0an+EnTbIJiYhQl1/7Fa1tlKiMm6VzuscW2WPkO WyMQ0SrnapBVJx23/FynfgS2HMKDHjGPHsgby9oZg0K8MWaOiu7UukN27BDrRRHk pmV9seabFSyPTGJ1Z1c+rNO8nIUihTRdv5/20qVWreS6CPQy2IkuaUIvcyPrw/x2 eJZLRl5kd/EqTQ5lHIHL+MM5n0kU6kEP77RUR6bQ7oYsMKpx0o9g6fvQ4nLiG0pR ueL4Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrheeggdduudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkgggtugfgjgesmhekreertddtjeen ucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhh drnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepudelkeekgfdttdettdekgfdu vdeiffelteegjeeihfetheekveeftedtuddvhfeunecuffhomhgrihhnpegvnhhtvghrph hrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgpdhnsggprh gtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegrmhhithdrkhgr phhilhgrudeisehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvg hrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepmhhitghh rggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 30 Nov 2024 03:28:32 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1732955311; bh=TyD/B9IcNTvJVZyv3M18VxNpXaQDUGP/O5kw3N3IJkM=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=fb4+MW0HzAZvKuYaxcwBnvzhDlC6yR6uVBrbGrtpopDU9UNCY5GIQu9ufRRP6sO7V 93exA+wcViohJwqbcvVE4LPqSuo+kJ/OEAxWILQuHwktajXVfNBB/jiw6/EE+od/kk VvIkGSgvybwijpa3pt1UHk8h/Kt8Gjs5baQ5qMF9GhxL7uyN0AFmXiz6fvSCnDbGji kuW581Hd8evjbkXJO7sW5PvqvE0bXF88oSsTVJeNwyhWuycKQls9os+mhmDv+7dm+7 1fG5YjTBDryf+8txqJKRPiy6awKwPV7XVqkoWHZ2DiCSekzOWjQZQ/65HueqYtLsei ZarOalhKDiqOQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 4DE2995; Sat, 30 Nov 2024 09:28:31 +0100 (CET) Date: Sat, 30 Nov 2024 09:28:31 +0100 From: Alvaro Herrera To: Michael Paquier Cc: Postgres hackers , Amit Kapila Subject: Re: Memory leak in WAL sender with pgoutput (v10~) Message-ID: <202411300828.hwe55pzx5a4x@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="b7h7j34eaushnudd" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --b7h7j34eaushnudd Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2024-Nov-30, Michael Paquier wrote: > After sleeping on that, and because the leak is minimal, I'm thinking > about just applying the fix only on HEAD and call it a day. This > changes the structure of Publication so as we use a char[NAMEDATALEN] > rather than a char*, avoiding the pstrdup(), for the publication name > and free it in the list_free_deep() when reloading the list of > publications. I'm not sure about your proposed fix. Isn't it simpler to have another memory context which we can reset instead of doing list_free_deep()? It doesn't have to be a global memory context -- since this is not reentrant and not referenced anywhere else, it can be a simple static variable in that block, as in the attached. I ran the stock tests (no sysbench) and at least it doesn't crash. This should be easily backpatchable also, since there's no ABI change. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ --b7h7j34eaushnudd Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-untested-try-at-fixing-memleak.patch" From 3ed287180a007447bbee152177139cf1d4347625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= Date: Sat, 30 Nov 2024 09:02:10 +0100 Subject: [PATCH] untested try at fixing memleak --- src/backend/replication/pgoutput/pgoutput.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c index 5e23453f071..010b341e0f5 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -2063,12 +2063,16 @@ get_rel_sync_entry(PGOutputData *data, Relation relation) /* Reload publications if needed before use. */ if (!publications_valid) { - oldctx = MemoryContextSwitchTo(CacheMemoryContext); - if (data->publications) - { - list_free_deep(data->publications); - data->publications = NIL; - } + static MemoryContext pubmemcxt = NULL; + + if (pubmemcxt == NULL) + pubmemcxt = AllocSetContextCreate(CacheMemoryContext, + "publication list context", + ALLOCSET_DEFAULT_SIZES); + else + MemoryContextReset(pubmemcxt); + oldctx = MemoryContextSwitchTo(pubmemcxt); + data->publications = LoadPublications(data->publication_names); MemoryContextSwitchTo(oldctx); publications_valid = true; -- 2.39.5 --b7h7j34eaushnudd--