Skip to content

Commit 369d494

Browse files
committed
Cleanup minor pg_dump memory leaks
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
1 parent a243c55 commit 369d494

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/bin/pg_dump/dumputils.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ buildACLCommands(const char *name, const char *subname, const char *nspname,
9595
{
9696
if (!parsePGArray(racls, &raclitems, &nraclitems))
9797
{
98+
if (aclitems)
99+
free(aclitems);
98100
if (raclitems)
99101
free(raclitems);
100102
return false;

src/bin/pg_dump/pg_dump.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15303,8 +15303,6 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1530315303
int actual_atts; /* number of attrs in this CREATE statement */
1530415304
const char *reltypename;
1530515305
char *storage;
15306-
char *srvname;
15307-
char *ftoptions;
1530815306
int j,
1530915307
k;
1531015308

@@ -15361,6 +15359,9 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1536115359
}
1536215360
else
1536315361
{
15362+
char *ftoptions = NULL;
15363+
char *srvname = NULL;
15364+
1536415365
switch (tbinfo->relkind)
1536515366
{
1536615367
case RELKIND_FOREIGN_TABLE:
@@ -15397,13 +15398,9 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1539715398
}
1539815399
case RELKIND_MATVIEW:
1539915400
reltypename = "MATERIALIZED VIEW";
15400-
srvname = NULL;
15401-
ftoptions = NULL;
1540215401
break;
1540315402
default:
1540415403
reltypename = "TABLE";
15405-
srvname = NULL;
15406-
ftoptions = NULL;
1540715404
}
1540815405

1540915406
numParents = tbinfo->numParents;
@@ -15951,6 +15948,11 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1595115948
tbinfo->attfdwoptions[j]);
1595215949
}
1595315950
}
15951+
15952+
if (ftoptions)
15953+
free(ftoptions);
15954+
if (srvname)
15955+
free(srvname);
1595415956
}
1595515957

1595615958
/*

0 commit comments

Comments
 (0)