]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
amcheck: Fix memory leak with gin_index_check()
authorMichael Paquier <michael@paquier.xyz>
Mon, 6 Jul 2026 00:32:28 +0000 (09:32 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 6 Jul 2026 00:32:28 +0000 (09:32 +0900)
"prev_tuple" was overwritten with a new tuple coming from
CopyIndexTuple() on each loop, leaking memory for every tuple processed
on entry tree pages.  The function uses a dedicated memory context, but
this could leave unused large areas of memory while processing a large
GIN index, the larger the worse.

Oversight in 14ffaece0fb5.

Author: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Ewan Young <kdbase.hack@gmail.com>
Discussion: https://postgr.es/m/CALdSSPjTS6TYe5=5NfMUBYZyQu5cn=ABL6K5_OZjzGWqnwXeBw@mail.gmail.com
Backpatch-through: 18

contrib/amcheck/verify_gin.c

index abfad07d5e48f9615ba4a0e5c2b3f37655845af2..fa06689ed5b2919c8b3432a61f43201dfec238c6 100644 (file)
@@ -637,6 +637,9 @@ gin_check_parent_keys_consistency(Relation rel,
                                pfree(ipd);
                        }
 
+                       if (prev_tuple)
+                               pfree(prev_tuple);
+
                        prev_tuple = CopyIndexTuple(idxtuple);
                        prev_attnum = current_attnum;
                }