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