]> granicus.if.org Git - postgresql/commitdiff
pg_dump: Don't leak memory in buildDefaultACLCommands()
authorStephen Frost <sfrost@snowman.net>
Sun, 7 May 2017 02:58:12 +0000 (22:58 -0400)
committerStephen Frost <sfrost@snowman.net>
Sun, 7 May 2017 02:58:12 +0000 (22:58 -0400)
buildDefaultACLCommands() didn't destroy the string buffer created in
certain cases, leading to a memory leak.  Fix by destroying the buffer
before returning from the function.

Spotted by Coverity.

Author: Michael Paquier

Back-patch to 9.6 where buildDefaultACLCommands() was added.

src/bin/pg_dump/dumputils.c

index c74153acce209b2c9384a07c676a8d64e3e1fd9e..19534248ab7c4d8dd94e8f14d1ab7a313e178ba9 100644 (file)
@@ -390,13 +390,19 @@ buildDefaultACLCommands(const char *type, const char *nspname,
                appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n");
                if (!buildACLCommands("", NULL, type, initacls, initracls, owner,
                                                          prefix->data, remoteVersion, sql))
+               {
+                       destroyPQExpBuffer(prefix);
                        return false;
+               }
                appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
        }
 
        if (!buildACLCommands("", NULL, type, acls, racls, owner,
                                                  prefix->data, remoteVersion, sql))
+       {
+               destroyPQExpBuffer(prefix);
                return false;
+       }
 
        destroyPQExpBuffer(prefix);