summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2015-01-18 15:57:55 +0100
committerAndres Freund <andres@anarazel.de>2015-01-18 16:04:10 +0100
commit525b84c576e119de7f2b0d00e3a99d559771aa7b (patch)
tree29b9ea808e7f3404de08f57b73d252db24b91724 /src/bin
parentff44fba46c09c37dd9e60da1cb0b3a9339eb085f (diff)
downloadpostgresql-525b84c576e119de7f2b0d00e3a99d559771aa7b.tar.gz
Fix use of already freed memory when dumping a database's security label.
pg_dump.c:dumDatabase() called ArchiveEntry() with the results of a a query that was PQclear()ed a couple lines earlier. Backpatch to 9.2 where security labels for shared objects where introduced.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/pg_dump/pg_dump.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index dc062e67ee..1e330f243a 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -2476,25 +2476,29 @@ dumpDatabase(Archive *fout, DumpOptions *dopt)
dbCatId, 0, dbDumpId);
}
- PQclear(res);
-
/* Dump shared security label. */
if (!dopt->no_security_labels && fout->remoteVersion >= 90200)
{
- PQExpBuffer seclabelQry = createPQExpBuffer();
+ PGresult *shres;
+ PQExpBuffer seclabelQry;
+
+ seclabelQry = createPQExpBuffer();
buildShSecLabelQuery(conn, "pg_database", dbCatId.oid, seclabelQry);
- res = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
+ shres = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
resetPQExpBuffer(seclabelQry);
- emitShSecLabels(conn, res, seclabelQry, "DATABASE", datname);
+ emitShSecLabels(conn, shres, seclabelQry, "DATABASE", datname);
if (strlen(seclabelQry->data))
ArchiveEntry(fout, dbCatId, createDumpId(), datname, NULL, NULL,
dba, false, "SECURITY LABEL", SECTION_NONE,
seclabelQry->data, "", NULL,
&dbDumpId, 1, NULL, NULL);
destroyPQExpBuffer(seclabelQry);
+ PQclear(shres);
}
+ PQclear(res);
+
destroyPQExpBuffer(dbQry);
destroyPQExpBuffer(delQry);
destroyPQExpBuffer(creaQry);