Fix leakage of memory context header in find_all_inheritors().
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 16 May 2017 23:33:31 +0000 (19:33 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 16 May 2017 23:33:31 +0000 (19:33 -0400)
Commit 827d6f977 contained the same misunderstanding of hash_create's API
as commit 090010f2e.  As in 5d00b764c, remove the unnecessary layer of
memory context.  (This bug is less significant than the other one, since
the extra context would be under a relatively short-lived context, but
it's still a bug.)

src/backend/catalog/pg_inherits.c

index 827ad2a850e35eee24cac441f4d9ea8f655860d5..04214fc20313e6d84dd03ed8bf4bccb251cd78c2 100644 (file)
@@ -29,9 +29,9 @@
 #include "storage/lmgr.h"
 #include "utils/builtins.h"
 #include "utils/fmgroids.h"
+#include "utils/memutils.h"
 #include "utils/syscache.h"
 #include "utils/tqual.h"
-#include "utils/memutils.h"
 
 /*
  * Entry of a hash table used in find_all_inheritors. See below.
@@ -169,29 +169,19 @@ find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
    /* hash table for O(1) rel_oid -> rel_numparents cell lookup */
    HTAB           *seen_rels;
    HASHCTL         ctl;
-   MemoryContext   new_ctx;
    List       *rels_list,
               *rel_numparents;
    ListCell   *l;
 
-   /*
-    * We need a separate memory context for a hash table. This is because
-    * hash table is used only in this procedure. To free a memory we need to
-    * call hash_destroy which is just a wrapper around MemoryContextDelete.
-    */
-   new_ctx = AllocSetContextCreate(CurrentMemoryContext,
-                                   "FindAllInheritorsSeenRelsContext",
-                                   ALLOCSET_DEFAULT_SIZES);
-
    memset(&ctl, 0, sizeof(ctl));
    ctl.keysize = sizeof(Oid);
    ctl.entrysize = sizeof(SeenRelsEntry);
-   ctl.hcxt = new_ctx;
+   ctl.hcxt = CurrentMemoryContext;
 
-   seen_rels = hash_create(
-       "find_all_inheritors temporary table",
-       32, /* start small and extend */
-       &ctl, HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);
+   seen_rels = hash_create("find_all_inheritors temporary table",
+                           32, /* start small and extend */
+                           &ctl,
+                           HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);
 
    /*
     * We build a list starting with the given rel and adding all direct and