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.96) (envelope-from ) id 1w62v3-003tU9-1b for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Mar 2026 08:51:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w62v2-008Vv4-0F for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Mar 2026 08:51:52 +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.96) (envelope-from ) id 1w62v1-008Vuv-2N for pgsql-bugs@lists.postgresql.org; Fri, 27 Mar 2026 08:51:52 +0000 Received: from smtp.outgoing.loopia.se ([93.188.3.37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w62uz-00000001Rot-2h7p for pgsql-bugs@lists.postgresql.org; Fri, 27 Mar 2026 08:51:51 +0000 Received: from s807.loopia.se (localhost [127.0.0.1]) by s807.loopia.se (Postfix) with ESMTP id 1CAFE56C3E1 for ; Fri, 27 Mar 2026 09:51:49 +0100 (CET) Received: from s934.loopia.se (unknown [172.22.191.6]) by s807.loopia.se (Postfix) with ESMTP id 039B556D1DC; Fri, 27 Mar 2026 09:51:49 +0100 (CET) Received: from localhost (unknown [172.22.191.6]) by s934.loopia.se (Postfix) with ESMTP id E76187CEAC9; Fri, 27 Mar 2026 09:51:48 +0100 (CET) X-Virus-Scanned: amavis at amavis.loopia.se X-Spam-Flag: NO X-Spam-Score: -1.2 X-Spam-Level: X-Spam-Status: No, score=-1.2 tagged_above=-999 required=6.2 tests=[ALL_TRUSTED=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1] autolearn=disabled Authentication-Results: s470.loopia.se (amavis); dkim=pass (2048-bit key) header.d=yesql.se Received: from s934.loopia.se ([172.22.191.6]) by localhost (s470.loopia.se [172.22.190.34]) (amavis, port 10024) with LMTP id V9iOhvcJKOfc; Fri, 27 Mar 2026 09:51:48 +0100 (CET) X-Loopia-Auth: user X-Loopia-User: daniel@yesql.se X-Loopia-Originating-IP: 89.255.232.236 Received: from smtpclient.apple (customer-89-255-232-236.stosn.net [89.255.232.236]) (Authenticated sender: daniel@yesql.se) by s934.loopia.se (Postfix) with ESMTPSA id 22BF27CEAB7; Fri, 27 Mar 2026 09:51:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yesql.se; s=loopiadkim1707475645; t=1774601508; bh=Jyh9X6Sjd8GF92lrq9m7nJPu36KRIp+wCi03MYho4Wc=; h=Subject:From:In-Reply-To:Date:Cc:References:To; b=auaWw0Z2xtUwIMW/oKqvbdaPOhVZUbKuU4AegUMKy5eWNx46sH8110MObBK10CXoo O9oIlmbA3E7D9M1PkaA1AEKpBLEOkspVnaa4J2AOOH1PJG/dbER3hyxKH2QFegle+g uMM2e9WWahbtGSsCDkPXprEisxiHOaYuGrRrt3UaylXPG+aaafkiy/QeeBb9a9O0NB u2taK8OTYnGSbAsrmOc3oVRAoNeI+DFilSGnxAi+O+9BERvWwbiIJKlZpbMlCSayOS CHDO3oZNgQjwix3gCzQZ77o/ur81VmX0X/zcYiQt30AJZ83U5rj6W6hmSPO7k6Hgtg 1NZLKdH59Y5lQ== Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51.11.2\)) Subject: Re: Memory leak in pg_stat_statements when qtext file contains invalid encoding From: Daniel Gustafsson In-Reply-To: Date: Fri, 27 Mar 2026 09:51:37 +0100 Cc: Gaurav Singh , pgsql-bugs@lists.postgresql.org Content-Transfer-Encoding: 7bit Message-Id: <91A12197-68B4-4C9E-8F5B-DB26D9FA30C5@yesql.se> References: To: Lukas Fittl X-Mailer: Apple Mail (2.3776.700.51.11.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 27 Mar 2026, at 09:21, Lukas Fittl wrote: > But I think you're correct about qbuffer - because that buffer is > using malloc (not palloc), its not part of any memory context, and so > it will happily leak on abort. > > It appears our use of malloc in pg_stat_statements is so that we can > fail on OOM and return NULL without a jump. I think that makes sense > for when a GC cycle was triggered during regular query execution > (since we don't want to error the original query), but it seems like > just bubbling up the OOM if needed when querying the > pg_stat_statements function seems fine. We could also use palloc_extended() with MCXT_ALLOC_NO_OOM to avoid erroring out on OOM and be able to return NULL? -- Daniel Gustafsson