]> granicus.if.org Git - postgresql/commitdiff
Cleanup minor pg_dump memory leaks
authorStephen Frost <sfrost@snowman.net>
Thu, 6 Dec 2018 16:11:21 +0000 (11:11 -0500)
committerStephen Frost <sfrost@snowman.net>
Thu, 6 Dec 2018 16:11:21 +0000 (11:11 -0500)
In dumputils, we may have successfully parsed the acls when we discover
that we can't parse the reverse ACLs and then return- check and free
aclitems if that happens.

In dumpTableSchema, move ftoptions and srvname under the relkind !=
RELKIND_VIEW branch (since they're only used there) and then check if
they've been allocated and, if so, free them at the end of that block.

Pointed out by Pavel Raiskup, though I didn't use those patches.

Discussion: https://postgr.es/m/2183976.vkCJMhdhmF@nb.usersys.redhat.com

src/bin/pg_dump/dumputils.c
src/bin/pg_dump/pg_dump.c

index 8a93ace9fa0bfec608c6517e89cccede01b8f87d..475d6dbd737cc519c152352c756a57c0a41c335b 100644 (file)
@@ -95,6 +95,8 @@ buildACLCommands(const char *name, const char *subname, const char *nspname,
        {
                if (!parsePGArray(racls, &raclitems, &nraclitems))
                {
+                       if (aclitems)
+                               free(aclitems);
                        if (raclitems)
                                free(raclitems);
                        return false;
index d583154fba052d9be22ff693f8e41cbe2644950d..637c79af48349a2cc723c7a3bd70fc7be4c56b86 100644 (file)
@@ -15303,8 +15303,6 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
        int                     actual_atts;    /* number of attrs in this CREATE statement */
        const char *reltypename;
        char       *storage;
-       char       *srvname;
-       char       *ftoptions;
        int                     j,
                                k;
 
@@ -15361,6 +15359,9 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
        }
        else
        {
+               char       *ftoptions = NULL;
+               char       *srvname = NULL;
+
                switch (tbinfo->relkind)
                {
                        case RELKIND_FOREIGN_TABLE:
@@ -15397,13 +15398,9 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
                                }
                        case RELKIND_MATVIEW:
                                reltypename = "MATERIALIZED VIEW";
-                               srvname = NULL;
-                               ftoptions = NULL;
                                break;
                        default:
                                reltypename = "TABLE";
-                               srvname = NULL;
-                               ftoptions = NULL;
                }
 
                numParents = tbinfo->numParents;
@@ -15951,6 +15948,11 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
                                                                  tbinfo->attfdwoptions[j]);
                        }
                }
+
+               if (ftoptions)
+                       free(ftoptions);
+               if (srvname)
+                       free(srvname);
        }
 
        /*