Commit f712289f authored by Heikki Linnakangas's avatar Heikki Linnakangas

Plug some trivial memory leaks in pg_dump and pg_upgrade.

There's no point in trying to free every small allocation in these
programs that are used in a one-shot fashion, but these ones seems like
an improvement on readability grounds.

Michael Paquier, per Coverity report.
parent 1fd0d5ec
......@@ -10593,6 +10593,8 @@ dumpCast(Archive *fout, DumpOptions *dopt, CastInfo *cast)
PQExpBuffer delqry;
PQExpBuffer labelq;
FuncInfo *funcInfo = NULL;
char *sourceType;
char *targetType;
/* Skip if not to be dumped */
if (!cast->dobj.dump || dopt->dataOnly)
......@@ -10616,13 +10618,13 @@ dumpCast(Archive *fout, DumpOptions *dopt, CastInfo *cast)
delqry = createPQExpBuffer();
labelq = createPQExpBuffer();
sourceType = getFormattedTypeName(fout, cast->castsource, zeroAsNone);
targetType = getFormattedTypeName(fout, cast->casttarget, zeroAsNone);
appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
getFormattedTypeName(fout, cast->castsource, zeroAsNone),
getFormattedTypeName(fout, cast->casttarget, zeroAsNone));
sourceType, targetType);
appendPQExpBuffer(defqry, "CREATE CAST (%s AS %s) ",
getFormattedTypeName(fout, cast->castsource, zeroAsNone),
getFormattedTypeName(fout, cast->casttarget, zeroAsNone));
sourceType, targetType);
switch (cast->castmethod)
{
......@@ -10660,8 +10662,7 @@ dumpCast(Archive *fout, DumpOptions *dopt, CastInfo *cast)
appendPQExpBufferStr(defqry, ";\n");
appendPQExpBuffer(labelq, "CAST (%s AS %s)",
getFormattedTypeName(fout, cast->castsource, zeroAsNone),
getFormattedTypeName(fout, cast->casttarget, zeroAsNone));
sourceType, targetType);
if (dopt->binary_upgrade)
binary_upgrade_extension_member(defqry, &cast->dobj, labelq->data);
......@@ -10679,6 +10680,9 @@ dumpCast(Archive *fout, DumpOptions *dopt, CastInfo *cast)
NULL, "",
cast->dobj.catId, 0, cast->dobj.dumpId);
free(sourceType);
free(targetType);
destroyPQExpBuffer(defqry);
destroyPQExpBuffer(delqry);
destroyPQExpBuffer(labelq);
......@@ -10696,6 +10700,7 @@ dumpTransform(Archive *fout, DumpOptions *dopt, TransformInfo *transform)
FuncInfo *fromsqlFuncInfo = NULL;
FuncInfo *tosqlFuncInfo = NULL;
char *lanname;
char *transformType;
/* Skip if not to be dumped */
if (!transform->dobj.dump || dopt->dataOnly)
......@@ -10723,14 +10728,13 @@ dumpTransform(Archive *fout, DumpOptions *dopt, TransformInfo *transform)
labelq = createPQExpBuffer();
lanname = get_language_name(fout, transform->trflang);
transformType = getFormattedTypeName(fout, transform->trftype, zeroAsNone);
appendPQExpBuffer(delqry, "DROP TRANSFORM FOR %s LANGUAGE %s;\n",
getFormattedTypeName(fout, transform->trftype, zeroAsNone),
lanname);
transformType, lanname);
appendPQExpBuffer(defqry, "CREATE TRANSFORM FOR %s LANGUAGE %s (",
getFormattedTypeName(fout, transform->trftype, zeroAsNone),
lanname);
transformType, lanname);
if (!transform->trffromsql && !transform->trftosql)
write_msg(NULL, "WARNING: bogus transform definition, at least one of trffromsql and trftosql should be nonzero\n");
......@@ -10777,8 +10781,7 @@ dumpTransform(Archive *fout, DumpOptions *dopt, TransformInfo *transform)
appendPQExpBuffer(defqry, ");\n");
appendPQExpBuffer(labelq, "TRANSFORM FOR %s LANGUAGE %s",
getFormattedTypeName(fout, transform->trftype, zeroAsNone),
lanname);
transformType, lanname);
if (dopt->binary_upgrade)
binary_upgrade_extension_member(defqry, &transform->dobj, labelq->data);
......@@ -10797,6 +10800,7 @@ dumpTransform(Archive *fout, DumpOptions *dopt, TransformInfo *transform)
transform->dobj.catId, 0, transform->dobj.dumpId);
free(lanname);
free(transformType);
destroyPQExpBuffer(defqry);
destroyPQExpBuffer(delqry);
destroyPQExpBuffer(labelq);
......
......@@ -1442,6 +1442,13 @@ dumpCreateDB(PGconn *conn)
free(fdbname);
}
if (default_encoding)
free(default_encoding);
if (default_collate)
free(default_collate);
if (default_ctype)
free(default_ctype);
PQclear(res);
destroyPQExpBuffer(buf);
......
......@@ -337,8 +337,14 @@ equivalent_locale(int category, const char *loca, const char *locb)
lenb = charb ? (charb - canonb) : strlen(canonb);
if (lena == lenb && pg_strncasecmp(canona, canonb, lena) == 0)
{
pg_free(canona);
pg_free(canonb);
return true;
}
pg_free(canona);
pg_free(canonb);
return false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment