Skip to content

Commit 821386a

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 c8ef5b1 commit 821386a

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
@@ -2112,25 +2112,29 @@ dumpDatabase(Archive *fout)
21122112
dbCatId, 0, dbDumpId);
21132113
}
21142114

2115-
PQclear(res);
2116-
21172115
/* Dump shared security label. */
21182116
if (!no_security_labels && fout->remoteVersion >= 90200)
21192117
{
2120-
PQExpBuffer seclabelQry = createPQExpBuffer();
2118+
PGresult *shres;
2119+
PQExpBuffer seclabelQry;
2120+
2121+
seclabelQry = createPQExpBuffer();
21212122

21222123
buildShSecLabelQuery(conn, "pg_database", dbCatId.oid, seclabelQry);
2123-
res = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
2124+
shres = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
21242125
resetPQExpBuffer(seclabelQry);
2125-
emitShSecLabels(conn, res, seclabelQry, "DATABASE", datname);
2126+
emitShSecLabels(conn, shres, seclabelQry, "DATABASE", datname);
21262127
if (strlen(seclabelQry->data))
21272128
ArchiveEntry(fout, dbCatId, createDumpId(), datname, NULL, NULL,
21282129
dba, false, "SECURITY LABEL", SECTION_NONE,
21292130
seclabelQry->data, "", NULL,
21302131
&dbDumpId, 1, NULL, NULL);
21312132
destroyPQExpBuffer(seclabelQry);
2133+
PQclear(shres);
21322134
}
21332135

2136+
PQclear(res);
2137+
21342138
destroyPQExpBuffer(dbQry);
21352139
destroyPQExpBuffer(delQry);
21362140
destroyPQExpBuffer(creaQry);

0 commit comments

Comments
 (0)