Fix uninitialized memory bug
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 22 Apr 2021 20:04:48 +0000 (16:04 -0400)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 22 Apr 2021 20:04:48 +0000 (16:04 -0400)
Have interested callers of find_inheritance_children set the
detached_exist value to false prior to calling it, so that that routine
only has to set it true in the rare cases where it is necessary.  Don't
touch it otherwise.

Per buildfarm member thorntail (which reported a UBSan failure here).

src/backend/catalog/pg_inherits.c
src/backend/partitioning/partdesc.c

index 98bf48d1e2bb3467f88ff74a9d94277c7b998480..6447b52854635999e0fafad1cb1dbef0d3c15686 100644 (file)
@@ -53,7 +53,7 @@ typedef struct SeenRelsEntry
  * against possible DROPs of child relations.
  *
  * If a partition's pg_inherits row is marked "detach pending",
- * *detached_exist (if not null) is set true, otherwise it is set false.
+ * *detached_exist (if not null) is set true.
  *
  * If omit_detached is true and there is an active snapshot (not the same as
  * the catalog snapshot used to scan pg_inherits!) and a pg_inherits tuple
@@ -84,9 +84,6 @@ find_inheritance_children(Oid parentrelId, bool omit_detached,
    if (!has_subclass(parentrelId))
        return NIL;
 
-   if (detached_exist)
-       *detached_exist = false;
-
    /*
     * Scan pg_inherits and build a working array of subclass OIDs.
     */
index 12ef36a73e63f5904aa7878d7bb582af0c280e4a..2305dff40770b3459a0e959d1955c43af3338f26 100644 (file)
@@ -131,6 +131,7 @@ RelationBuildPartitionDesc(Relation rel, bool omit_detached)
     * concurrently, whatever this function returns will be accurate as of
     * some well-defined point in time.
     */
+   detached_exist = false;
    inhoids = find_inheritance_children(RelationGetRelid(rel), omit_detached,
                                        NoLock, &detached_exist);
    nparts = list_length(inhoids);