]> granicus.if.org Git - postgresql/commitdiff
Fix bogus size calculation in strlist_to_textarray().
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 23 Sep 2017 19:01:59 +0000 (15:01 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 23 Sep 2017 19:01:59 +0000 (15:01 -0400)
It's making an array of Datum, not an array of text *.  The mistake
is harmless since those are currently the same size, but it's still
wrong.

src/backend/catalog/objectaddress.c

index 6cac2dfd1db6ced3006ca8525100e059cfca1c95..c2ad7c675e531e6d13fbaf9282cec7771d8bf70e 100644 (file)
@@ -5051,7 +5051,7 @@ getRelationIdentity(StringInfo buffer, Oid relid, List **object)
 }
 
 /*
- * Auxiliary function to return a TEXT array out of a list of C-strings.
+ * Auxiliary function to build a TEXT array out of a list of C-strings.
  */
 ArrayType *
 strlist_to_textarray(List *list)
@@ -5063,12 +5063,14 @@ strlist_to_textarray(List *list)
        MemoryContext memcxt;
        MemoryContext oldcxt;
 
+       /* Work in a temp context; easier than individually pfree'ing the Datums */
        memcxt = AllocSetContextCreate(CurrentMemoryContext,
                                                                   "strlist to array",
                                                                   ALLOCSET_DEFAULT_SIZES);
        oldcxt = MemoryContextSwitchTo(memcxt);
 
-       datums = palloc(sizeof(text *) * list_length(list));
+       datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
+
        foreach(cell, list)
        {
                char       *name = lfirst(cell);
@@ -5080,6 +5082,7 @@ strlist_to_textarray(List *list)
 
        arr = construct_array(datums, list_length(list),
                                                  TEXTOID, -1, false, 'i');
+
        MemoryContextDelete(memcxt);
 
        return arr;