Skip to content

Commit acfaa59

Browse files
committed
pg_dump: Fix some minor memory leaks
Although we often don't care about freeing all memory in pg_dump, these functions already freed the same memory in other code paths, so we might as well do it consistently. found by Coverity
1 parent 5cd72c7 commit acfaa59

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,7 +3169,7 @@ getCollations(Archive *fout, int *numCollations)
31693169
PGresult *res;
31703170
int ntups;
31713171
int i;
3172-
PQExpBuffer query = createPQExpBuffer();
3172+
PQExpBuffer query;
31733173
CollInfo *collinfo;
31743174
int i_tableoid;
31753175
int i_oid;
@@ -3184,6 +3184,8 @@ getCollations(Archive *fout, int *numCollations)
31843184
return NULL;
31853185
}
31863186

3187+
query = createPQExpBuffer();
3188+
31873189
/*
31883190
* find all collations, including builtin collations; we filter out
31893191
* system-defined collations at dump-out time.
@@ -6167,7 +6169,7 @@ getTSParsers(Archive *fout, int *numTSParsers)
61676169
PGresult *res;
61686170
int ntups;
61696171
int i;
6170-
PQExpBuffer query = createPQExpBuffer();
6172+
PQExpBuffer query;
61716173
TSParserInfo *prsinfo;
61726174
int i_tableoid;
61736175
int i_oid;
@@ -6186,6 +6188,8 @@ getTSParsers(Archive *fout, int *numTSParsers)
61866188
return NULL;
61876189
}
61886190

6191+
query = createPQExpBuffer();
6192+
61896193
/*
61906194
* find all text search objects, including builtin ones; we filter out
61916195
* system-defined objects at dump-out time.
@@ -6257,7 +6261,7 @@ getTSDictionaries(Archive *fout, int *numTSDicts)
62576261
PGresult *res;
62586262
int ntups;
62596263
int i;
6260-
PQExpBuffer query = createPQExpBuffer();
6264+
PQExpBuffer query;
62616265
TSDictInfo *dictinfo;
62626266
int i_tableoid;
62636267
int i_oid;
@@ -6274,6 +6278,8 @@ getTSDictionaries(Archive *fout, int *numTSDicts)
62746278
return NULL;
62756279
}
62766280

6281+
query = createPQExpBuffer();
6282+
62776283
/* Make sure we are in proper schema */
62786284
selectSourceSchema(fout, "pg_catalog");
62796285

@@ -6340,7 +6346,7 @@ getTSTemplates(Archive *fout, int *numTSTemplates)
63406346
PGresult *res;
63416347
int ntups;
63426348
int i;
6343-
PQExpBuffer query = createPQExpBuffer();
6349+
PQExpBuffer query;
63446350
TSTemplateInfo *tmplinfo;
63456351
int i_tableoid;
63466352
int i_oid;
@@ -6356,6 +6362,8 @@ getTSTemplates(Archive *fout, int *numTSTemplates)
63566362
return NULL;
63576363
}
63586364

6365+
query = createPQExpBuffer();
6366+
63596367
/* Make sure we are in proper schema */
63606368
selectSourceSchema(fout, "pg_catalog");
63616369

@@ -6415,7 +6423,7 @@ getTSConfigurations(Archive *fout, int *numTSConfigs)
64156423
PGresult *res;
64166424
int ntups;
64176425
int i;
6418-
PQExpBuffer query = createPQExpBuffer();
6426+
PQExpBuffer query;
64196427
TSConfigInfo *cfginfo;
64206428
int i_tableoid;
64216429
int i_oid;
@@ -6431,6 +6439,8 @@ getTSConfigurations(Archive *fout, int *numTSConfigs)
64316439
return NULL;
64326440
}
64336441

6442+
query = createPQExpBuffer();
6443+
64346444
/* Make sure we are in proper schema */
64356445
selectSourceSchema(fout, "pg_catalog");
64366446

@@ -9467,16 +9477,18 @@ dumpCast(Archive *fout, CastInfo *cast)
94679477
appendPQExpBuffer(defqry, "WITH INOUT");
94689478
break;
94699479
case COERCION_METHOD_FUNCTION:
9480+
{
9481+
char *fsig = format_function_signature(fout, funcInfo, true);
94709482

94719483
/*
94729484
* Always qualify the function name, in case it is not in
94739485
* pg_catalog schema (format_function_signature won't qualify it).
94749486
*/
9475-
appendPQExpBuffer(defqry, "WITH FUNCTION %s.",
9476-
fmtId(funcInfo->dobj.namespace->dobj.name));
9477-
appendPQExpBuffer(defqry, "%s",
9478-
format_function_signature(fout, funcInfo, true));
9487+
appendPQExpBuffer(defqry, "WITH FUNCTION %s.%s",
9488+
fmtId(funcInfo->dobj.namespace->dobj.name), fsig);
9489+
free(fsig);
94799490
break;
9491+
}
94809492
default:
94819493
write_msg(NULL, "WARNING: bogus value in pg_cast.castmethod field\n");
94829494
}

src/bin/pg_dump/pg_dumpall.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,12 +1525,17 @@ makeAlterConfigCommand(PGconn *conn, const char *arrayitem,
15251525
{
15261526
char *pos;
15271527
char *mine;
1528-
PQExpBuffer buf = createPQExpBuffer();
1528+
PQExpBuffer buf;
15291529

15301530
mine = pg_strdup(arrayitem);
15311531
pos = strchr(mine, '=');
15321532
if (pos == NULL)
1533+
{
1534+
free(mine);
15331535
return;
1536+
}
1537+
1538+
buf = createPQExpBuffer();
15341539

15351540
*pos = 0;
15361541
appendPQExpBuffer(buf, "ALTER %s %s ", type, fmtId(name));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy