]> granicus.if.org Git - postgresql/commitdiff
Plug some trivial memory leaks in pg_dump and pg_upgrade.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 2 Jul 2015 17:58:51 +0000 (20:58 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 2 Jul 2015 17:58:51 +0000 (20:58 +0300)
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.

src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dumpall.c
src/bin/pg_upgrade/check.c

index 32ac26f1db476cb34370ac82049d73f2575ef187..b5c529bb8efe20dd409bdde058d7236c70225271 100644 (file)
@@ -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);
index d98c83e099c6439b17e4a3f736470ea22d40ab98..c4b6ae85aa7d649f399009da6d3dff4044d320a1 100644 (file)
@@ -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);
 
index 5a91871c35989b3ef35708ac4c3deaeb81f7e74b..41d4606dd592422f25fe86a503cd5e1948c44c7b 100644 (file)
@@ -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;
 }