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 1rtdQV-00GLaC-G0 for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Apr 2024 01:04:00 +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 1rtdQU-00Evn9-FG for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Apr 2024 01:03:58 +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 1rtdQU-00Evn0-5t for pgsql-hackers@lists.postgresql.org; Mon, 08 Apr 2024 01:03:58 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtdQR-001joX-Of for pgsql-hackers@lists.postgresql.org; Mon, 08 Apr 2024 01:03:56 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 43813raX3005249; Sun, 7 Apr 2024 21:03:53 -0400 From: Tom Lane To: Andres Freund cc: pgsql-hackers@lists.postgresql.org Subject: Coverity complains about simplehash.h's SH_STAT() MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3005247.1712538233.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 07 Apr 2024 21:03:53 -0400 Message-ID: <3005248.1712538233@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Today's Coverity run produced this: /srv/coverity/git/pgsql-git/postgresql/src/include/lib/simplehash.h: 1138 = in bh_nodeidx_stat() 1132 avg_collisions =3D 0; 1133 } 1134 = 1135 sh_log("size: " UINT64_FORMAT ", members: %u, filled: %f, tot= al chain: %u, max chain: %u, avg chain: %f, total_collisions: %u, max_coll= isions: %u, avg_collisions: %f", 1136 tb->size, tb->members, fillfactor, total_chain_length,= max_chain_length, avg_chain_length, 1137 total_collisions, max_collisions, avg_collisions); >>> CID 1596268: Resource leaks (RESOURCE_LEAK) >>> Variable "collisions" going out of scope leaks the storage it poin= ts to. 1138 } 1139 = 1140 #endif /* SH_DEFINE */ I have no idea why we didn't see this warning before --- but AFAICS it's quite right, and it looks like a nontrivial amount of memory could be at stake: uint32 *collisions =3D (uint32 *) palloc0(tb->size * sizeof(uint= 32)); I realize this function is only debug support, but wouldn't it be appropriate to pfree(collisions) before exiting? regards, tom lane