simplehash: Free collisions array in SH_STAT
authorAndres Freund <andres@anarazel.de>
Mon, 8 Apr 2024 02:00:11 +0000 (19:00 -0700)
committerAndres Freund <andres@anarazel.de>
Mon, 8 Apr 2024 02:09:05 +0000 (19:09 -0700)
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-

src/include/lib/simplehash.h

index 548526f76159b5e5c02c06c6664a64329f3ce353..85a1448d2fbcb6c46bcc5a0a0fdcd0f699d13382 100644 (file)
@@ -1102,6 +1102,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);