From: Andres Freund <andres@anarazel.de>
Date: Mon, 8 Apr 2024 02:00:11 +0000 (-0700)
Subject: simplehash: Free collisions array in SH_STAT
X-Git-Tag: REL_13_15~24
X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=eabf98e949e3a655494a32ceb8d146117cce0505;p=postgresql.git

simplehash: Free collisions array in SH_STAT

While SH_STAT() is only used for debugging, the allocated array can be large,
and therefore should be freed.

It's unclear why coverity started warning now.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Reported-by: Coverity
Discussion: https://postgr.es/m/3005248.1712538233@sss.pgh.pa.us
Backpatch: 12-
---

diff --git a/src/include/lib/simplehash.h b/src/include/lib/simplehash.h
index b4573187c63..5373dac3445 100644
--- a/src/include/lib/simplehash.h
+++ b/src/include/lib/simplehash.h
@@ -977,6 +977,9 @@ SH_STAT(SH_TYPE * tb)
 			max_collisions = curcoll;
 	}
 
+	/* large enough to be worth freeing, even if just used for debugging */
+	pfree(collisions);
+
 	if (tb->members > 0)
 	{
 		fillfactor = tb->members / ((double) tb->size);