minor leaks in pg_dump (PG tarball 10.6) - Mailing list pgsql-hackers

From Pavel Raiskup
Subject minor leaks in pg_dump (PG tarball 10.6)
Date
Msg-id 2183976.vkCJMhdhmF@nb.usersys.redhat.com
Whole thread Raw
Responses Re: minor leaks in pg_dump (PG tarball 10.6)
List pgsql-hackers
Among other reports (IMO clearly non-issues), I'm sending patch which
fixes/points to a few resource leaks detected by Coverity that might be
worth fixing.  If they are not, feel free to ignore this mail.

Pavel

diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c
index 8a93ace9fa..475d6dbd73 100644
--- a/src/bin/pg_dump/dumputils.c
+++ b/src/bin/pg_dump/dumputils.c
@@ -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;
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index d583154fba..731a08c15c 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -8284,7 +8284,6 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
             res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK);
 
             numDefaults = PQntuples(res);
-            attrdefs = (AttrDefInfo *) pg_malloc(numDefaults * sizeof(AttrDefInfo));
 
             for (j = 0; j < numDefaults; j++)
             {
@@ -8304,6 +8303,8 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
                 if (tbinfo->attisdropped[adnum - 1])
                     continue;
 
+                attrdefs = (AttrDefInfo *) pg_malloc(numDefaults * sizeof(AttrDefInfo));
+
                 attrdefs[j].dobj.objType = DO_ATTRDEF;
                 attrdefs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, 0));
                 attrdefs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, 1));
@@ -15951,6 +15952,9 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
                                   tbinfo->attfdwoptions[j]);
             }
         }
+
+        free(ftoptions);
+        free(srvname);
     }
 
     /*





pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: don't mark indexes invalid unnecessarily
Next
From: Stephen Frost
Date:
Subject: Re: minor leaks in pg_dump (PG tarball 10.6)