Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 94bc1c5

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 6bbf751 commit 94bc1c5

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
@@ -2465,25 +2465,29 @@ dumpDatabase(Archive *fout)
24652465
dbCatId, 0, dbDumpId);
24662466
}
24672467

2468-
PQclear(res);
2469-
24702468
/* Dump shared security label. */
24712469
if (!no_security_labels && fout->remoteVersion >= 90200)
24722470
{
2473-
PQExpBuffer seclabelQry = createPQExpBuffer();
2471+
PGresult *shres;
2472+
PQExpBuffer seclabelQry;
2473+
2474+
seclabelQry = createPQExpBuffer();
24742475

24752476
buildShSecLabelQuery(conn, "pg_database", dbCatId.oid, seclabelQry);
2476-
res = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
2477+
shres = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
24772478
resetPQExpBuffer(seclabelQry);
2478-
emitShSecLabels(conn, res, seclabelQry, "DATABASE", datname);
2479+
emitShSecLabels(conn, shres, seclabelQry, "DATABASE", datname);
24792480
if (strlen(seclabelQry->data))
24802481
ArchiveEntry(fout, dbCatId, createDumpId(), datname, NULL, NULL,
24812482
dba, false, "SECURITY LABEL", SECTION_NONE,
24822483
seclabelQry->data, "", NULL,
24832484
&dbDumpId, 1, NULL, NULL);
24842485
destroyPQExpBuffer(seclabelQry);
2486+
PQclear(shres);
24852487
}
24862488

2489+
PQclear(res);
2490+
24872491
destroyPQExpBuffer(dbQry);
24882492
destroyPQExpBuffer(delQry);
24892493
destroyPQExpBuffer(creaQry);

0 commit comments

Comments
 (0)