Skip to content

Commit 525b84c

Browse files
committed
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.
1 parent ff44fba commit 525b84c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,25 +2476,29 @@ dumpDatabase(Archive *fout, DumpOptions *dopt)
24762476
dbCatId, 0, dbDumpId);
24772477
}
24782478

2479-
PQclear(res);
2480-
24812479
/* Dump shared security label. */
24822480
if (!dopt->no_security_labels && fout->remoteVersion >= 90200)
24832481
{
2484-
PQExpBuffer seclabelQry = createPQExpBuffer();
2482+
PGresult *shres;
2483+
PQExpBuffer seclabelQry;
2484+
2485+
seclabelQry = createPQExpBuffer();
24852486

24862487
buildShSecLabelQuery(conn, "pg_database", dbCatId.oid, seclabelQry);
2487-
res = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
2488+
shres = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
24882489
resetPQExpBuffer(seclabelQry);
2489-
emitShSecLabels(conn, res, seclabelQry, "DATABASE", datname);
2490+
emitShSecLabels(conn, shres, seclabelQry, "DATABASE", datname);
24902491
if (strlen(seclabelQry->data))
24912492
ArchiveEntry(fout, dbCatId, createDumpId(), datname, NULL, NULL,
24922493
dba, false, "SECURITY LABEL", SECTION_NONE,
24932494
seclabelQry->data, "", NULL,
24942495
&dbDumpId, 1, NULL, NULL);
24952496
destroyPQExpBuffer(seclabelQry);
2497+
PQclear(shres);
24962498
}
24972499

2500+
PQclear(res);
2501+
24982502
destroyPQExpBuffer(dbQry);
24992503
destroyPQExpBuffer(delQry);
25002504
destroyPQExpBuffer(creaQry);

0 commit comments

Comments
 (0)