From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Coverity complains about simplehash.h's SH_STAT()
Date: Sun, 07 Apr 2024 21:03:53 -0400
Message-ID: <3005248.1712538233@sss.pgh.pa.us> (raw)
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 = 0;
1133 }
1134
1135 sh_log("size: " UINT64_FORMAT ", members: %u, filled: %f, total chain: %u, max chain: %u, avg chain: %f, total_collisions: %u, max_collisions: %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 points 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 = (uint32 *) palloc0(tb->size * sizeof(uint32));
I realize this function is only debug support, but wouldn't it
be appropriate to pfree(collisions) before exiting?
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, andres@anarazel.de
Subject: Re: Coverity complains about simplehash.h's SH_STAT()
In-Reply-To: <3005248.1712538233@sss.pgh.pa.us>
References: <3005248.1712538233@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox