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 1wh7p0-00019i-1B for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jul 2026 15:34:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wh7oy-001LI6-2v for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jul 2026 15:34:53 +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 1wh7oy-001LHy-0A for pgsql-hackers@lists.postgresql.org; Tue, 07 Jul 2026 15:34:53 +0000 Received: from fhigh-b2-smtp.messagingengine.com ([202.12.124.153]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wh7ov-000000003WT-08iR for pgsql-hackers@postgresql.org; Tue, 07 Jul 2026 15:34:52 +0000 Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id 692C97A007B; Tue, 7 Jul 2026 11:34:46 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Tue, 07 Jul 2026 11:34:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding: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=fm1; t=1783438486; x=1783524886; bh=RuX8f4QrgnM3wOTtLuqfUmzqLGw7vTcL fzWdUujzA/c=; b=GlPI5SCNaLLH4RxURaScHgB4mOqjGShHu6dCMH+iDWGg6hAo CNM8flYSeGDo1cOVSGxgMtjjZKmWfokpJNjV0zmjr97qdUJfgdJPdBEwrLLICCH/ O01YjfpJc5UM4TRT6QJu5Jtu370ex160R98yJZUbIpaW0NJFReEf2Cba13EV0liM ToshnKmiBqGcHBX9K61KmNuw7iPRfwY7ooW8uMrk3mUTyH4/tAZ26hTnHWGTBxoF 4dIqi3Xynqv7SiB6VhCWeqDjP10ozH1MyK2+gryd/u3A1bFiYBGJhlb334ChDrJz InzLWfq2hDLcWd5NzaKSYNpDf1kOACEw2u/VIA== 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 :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1783438486; x= 1783524886; bh=RuX8f4QrgnM3wOTtLuqfUmzqLGw7vTcLfzWdUujzA/c=; b=W 3Fm8uBibuxPIAGxHP1xRVuOUyMUdhSk2I+3y/L9dTkzPBDGoVeKii4KuYW4Gsq7x TX8clOyku9yHh1puZAiz3hrCMYn1PB/3oY3ntBI9CId6OopjjJfFXNYLhHTj5Waw GTX2XfgIE5w13WmXrI2wxMsQBHk7Mfsyo+Z4Kzx+4/MOi05yWqvqs4TdA5UUk/In sAjdFfQke6YaQJKcyWzNL/S7P9RDlAM4MLeEyLW9caoeQzzQRpFeFT18oT8bdkyL Sff0fnnvry/avL5Hk9gZUBZFVFLapkPVxYPkf6Pz8ucvUlrPjK6vBBN8gxChE9iY 0Xaf/3YJVcHW/cptaj5JA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEy+vV6qIOhidkehQ2Iha6oOY0TIlLUV1k3ClFqlDIOFdQAzs2f1yZ0bFX/qO5IaS nzhn3R8O4DtmCfltPbexjBK9rJzzjuB8sRnwGZB8YcGpo5HnCgxPsmlCFVIxx+F0D6qqJi 61TAlkeRxDuE7gmemas+jVqqaSxR5sSdW7BLRNhFsCLKxmKt/b3rYPua09onsLVlnmBUdV FQMCiUxKM3BtQXS770yDfMbdS6SrL1w5nGPfyr8MeDv7iBfu0oQ6HaZIIPIbJPOJzpajh+ Xy8GP5jzHz05QzHr8x8uDVm1gfqOC8n4OtUNgfSohIrZJTvFiVnf7P3oO4ZrKdSxphINMo l8czD1W2UOqLGRflRwea/jY8QpenlaS2+Q7d48pgXKX5bgbtp4D25P+T7BRFNNTlufvqBn PJmT0WPacVFewgbHgPrDlet61nhAx9/m0rqIrihLigAv7Kop3EKcsWnMoeRO78QmysnpG5 uUtfsWlvnWvu1DZcUUcuhutRUwzBZJF8+VJPiIgXHeHWuhwyDyZB70XnX+OAPQDvHBiDHg grR7gjEF21094/3Ta0IC+2csCNB4GHbmx6y8o+HN7xry+kTIB3u9tNDZ3UD7xruNulw514 TwP06KulS2kSuZ1w9OrzCUGkav9Qug4Y75xSaQwXaCMvz5Sxh/BaB0Zr4pgw X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 Jul 2026 11:34:45 -0400 (EDT) Message-ID: <2248c1c4-68f7-46dc-9e58-9ba9057da74e@eisentraut.org> Date: Tue, 7 Jul 2026 17:34:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Add malloc attribute to memory allocation functions To: Tristan Partin , Tom Lane Cc: pgsql-hackers References: <924283.1783312014@sss.pgh.pa.us> Content-Language: en-US From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 06.07.26 18:34, Tristan Partin wrote: > On Mon Jul 6, 2026 at 4:26 AM UTC, Tom Lane wrote: >> "Tristan Partin" writes: >>> Given that we now have a tree that compiles fine against >>> -Werror=mismatched-dealloc, we need to make sure that we don't regress. >>> By adding the malloc attribute[0], we can protect against regressions, >>> enable more accurate code coverage with -fanalyzer, and allow the >>> compiler to do some optimizations. >> >> I'm skeptical that this is going to lead to anything but grief. >> In particular, since gcc has never heard of memory contexts, >> I don't see how we are not going to get buried in bogus >> -Wanalyzer-malloc-leak warnings. It doesn't really help >> to add compiler annotations that only sort-of match our semantics. >> >> (This opinion is based on years of dismissing useless Coverity >> warnings of this kind.) > > This is a fair criticism. On master, the number of > -Wanalyzer-malloc-leak warnings is 62. With this patch applied, it > balloons to 598. But this can also check for a lot more, such as - mismatching deallocator - double free - use after free - free of things that are not an allocation If we could tell it, check for all these things but don't worry about the leaks, that could be useful. Also, for frontend tools, libpq, etc. that don't use memory contexts.