Plug memory leak in index_get_partition
authorAlvaro Herrera <[email protected]>
Sat, 7 Nov 2020 01:52:16 +0000 (22:52 -0300)
committerAlvaro Herrera <[email protected]>
Sat, 7 Nov 2020 01:52:16 +0000 (22:52 -0300)
The list of indexes was being leaked when asked for an index that
doesn't have an index partition in the table partition.  Not a common
case admittedly --and in most cases where it occurs, caller throws an
error anyway-- but worth fixing for cleanliness and in case any
third-party code is calling this function.

While at it, remove use of lfirst_oid() to obtain a value we already
have.

Author: Justin Pryzby <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/20201105203606[email protected]

src/backend/catalog/partition.c

index 239ac017fa69e5acbc2187c76b7fb642c4a2070b..4dfac39adfe48143c69ef7bd92a53ec9f030c4ff 100644 (file)
@@ -170,13 +170,14 @@ index_get_partition(Relation partition, Oid indexId)
        ReleaseSysCache(tup);
        if (!ispartition)
            continue;
-       if (get_partition_parent(lfirst_oid(l)) == indexId)
+       if (get_partition_parent(partIdx) == indexId)
        {
            list_free(idxlist);
            return partIdx;
        }
    }
 
+   list_free(idxlist);
    return InvalidOid;
 }