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
This commit is contained in:
Peter Eisentraut 2012-03-13 21:34:54 +02:00
parent 5cd72c7a7c
commit acfaa596cc
2 changed files with 27 additions and 10 deletions

View File

@ -3169,7 +3169,7 @@ getCollations(Archive *fout, int *numCollations)
PGresult *res;
int ntups;
int i;
PQExpBuffer query = createPQExpBuffer();
PQExpBuffer query;
CollInfo *collinfo;
int i_tableoid;
int i_oid;
@ -3184,6 +3184,8 @@ getCollations(Archive *fout, int *numCollations)
return NULL;
}
query = createPQExpBuffer();
/*
* find all collations, including builtin collations; we filter out
* system-defined collations at dump-out time.
@ -6167,7 +6169,7 @@ getTSParsers(Archive *fout, int *numTSParsers)
PGresult *res;
int ntups;
int i;
PQExpBuffer query = createPQExpBuffer();
PQExpBuffer query;
TSParserInfo *prsinfo;
int i_tableoid;
int i_oid;
@ -6186,6 +6188,8 @@ getTSParsers(Archive *fout, int *numTSParsers)
return NULL;
}
query = createPQExpBuffer();
/*
* find all text search objects, including builtin ones; we filter out
* system-defined objects at dump-out time.
@ -6257,7 +6261,7 @@ getTSDictionaries(Archive *fout, int *numTSDicts)
PGresult *res;
int ntups;
int i;
PQExpBuffer query = createPQExpBuffer();
PQExpBuffer query;
TSDictInfo *dictinfo;
int i_tableoid;
int i_oid;
@ -6274,6 +6278,8 @@ getTSDictionaries(Archive *fout, int *numTSDicts)
return NULL;
}
query = createPQExpBuffer();
/* Make sure we are in proper schema */
selectSourceSchema(fout, "pg_catalog");
@ -6340,7 +6346,7 @@ getTSTemplates(Archive *fout, int *numTSTemplates)
PGresult *res;
int ntups;
int i;
PQExpBuffer query = createPQExpBuffer();
PQExpBuffer query;
TSTemplateInfo *tmplinfo;
int i_tableoid;
int i_oid;
@ -6356,6 +6362,8 @@ getTSTemplates(Archive *fout, int *numTSTemplates)
return NULL;
}
query = createPQExpBuffer();
/* Make sure we are in proper schema */
selectSourceSchema(fout, "pg_catalog");
@ -6415,7 +6423,7 @@ getTSConfigurations(Archive *fout, int *numTSConfigs)
PGresult *res;
int ntups;
int i;
PQExpBuffer query = createPQExpBuffer();
PQExpBuffer query;
TSConfigInfo *cfginfo;
int i_tableoid;
int i_oid;
@ -6431,6 +6439,8 @@ getTSConfigurations(Archive *fout, int *numTSConfigs)
return NULL;
}
query = createPQExpBuffer();
/* Make sure we are in proper schema */
selectSourceSchema(fout, "pg_catalog");
@ -9467,16 +9477,18 @@ dumpCast(Archive *fout, CastInfo *cast)
appendPQExpBuffer(defqry, "WITH INOUT");
break;
case COERCION_METHOD_FUNCTION:
{
char *fsig = format_function_signature(fout, funcInfo, true);
/*
* Always qualify the function name, in case it is not in
* pg_catalog schema (format_function_signature won't qualify it).
*/
appendPQExpBuffer(defqry, "WITH FUNCTION %s.",
fmtId(funcInfo->dobj.namespace->dobj.name));
appendPQExpBuffer(defqry, "%s",
format_function_signature(fout, funcInfo, true));
appendPQExpBuffer(defqry, "WITH FUNCTION %s.%s",
fmtId(funcInfo->dobj.namespace->dobj.name), fsig);
free(fsig);
break;
}
default:
write_msg(NULL, "WARNING: bogus value in pg_cast.castmethod field\n");
}

View File

@ -1525,12 +1525,17 @@ makeAlterConfigCommand(PGconn *conn, const char *arrayitem,
{
char *pos;
char *mine;
PQExpBuffer buf = createPQExpBuffer();
PQExpBuffer buf;
mine = pg_strdup(arrayitem);
pos = strchr(mine, '=');
if (pos == NULL)
{
free(mine);
return;
}
buf = createPQExpBuffer();
*pos = 0;
appendPQExpBuffer(buf, "ALTER %s %s ", type, fmtId(name));