Skip to content

Commit 509da59

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 e32cb8d commit 509da59

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
@@ -2428,25 +2428,29 @@ dumpDatabase(Archive *fout)
24282428
dbCatId, 0, dbDumpId);
24292429
}
24302430

2431-
PQclear(res);
2432-
24332431
/* Dump shared security label. */
24342432
if (!no_security_labels && fout->remoteVersion >= 90200)
24352433
{
2436-
PQExpBuffer seclabelQry = createPQExpBuffer();
2434+
PGresult *shres;
2435+
PQExpBuffer seclabelQry;
2436+
2437+
seclabelQry = createPQExpBuffer();
24372438

24382439
buildShSecLabelQuery(conn, "pg_database", dbCatId.oid, seclabelQry);
2439-
res = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
2440+
shres = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
24402441
resetPQExpBuffer(seclabelQry);
2441-
emitShSecLabels(conn, res, seclabelQry, "DATABASE", datname);
2442+
emitShSecLabels(conn, shres, seclabelQry, "DATABASE", datname);
24422443
if (strlen(seclabelQry->data))
24432444
ArchiveEntry(fout, dbCatId, createDumpId(), datname, NULL, NULL,
24442445
dba, false, "SECURITY LABEL", SECTION_NONE,
24452446
seclabelQry->data, "", NULL,
24462447
&dbDumpId, 1, NULL, NULL);
24472448
destroyPQExpBuffer(seclabelQry);
2449+
PQclear(shres);
24482450
}
24492451

2452+
PQclear(res);
2453+
24502454
destroyPQExpBuffer(dbQry);
24512455
destroyPQExpBuffer(delQry);
24522456
destroyPQExpBuffer(creaQry);

0 commit comments

Comments
 (0)