Skip to content

Commit 78bfc22

Browse files
committed
Fix use-after-free error reported by Neil Conway.
1 parent 569e32a commit 78bfc22

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/bin/psql/common.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.119 2006/06/14 16:49:02 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.120 2006/06/30 15:06:05 alvherre Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "common.h"
@@ -875,19 +875,19 @@ SendQuery(const char *query)
875875
if (OK)
876876
OK = PrintQueryResults(results);
877877

878-
PQclear(results);
879-
880878
/* If we made a temporary savepoint, possibly release/rollback */
881879
if (on_error_rollback_savepoint)
882880
{
881+
PGresult *svptres;
882+
883883
transaction_status = PQtransactionStatus(pset.db);
884884

885885
/* We always rollback on an error */
886886
if (transaction_status == PQTRANS_INERROR)
887-
results = PQexec(pset.db, "ROLLBACK TO pg_psql_temporary_savepoint");
887+
svptres = PQexec(pset.db, "ROLLBACK TO pg_psql_temporary_savepoint");
888888
/* If they are no longer in a transaction, then do nothing */
889889
else if (transaction_status != PQTRANS_INTRANS)
890-
results = NULL;
890+
svptres = NULL;
891891
else
892892
{
893893
/*
@@ -898,20 +898,22 @@ SendQuery(const char *query)
898898
if (strcmp(PQcmdStatus(results), "SAVEPOINT") == 0 ||
899899
strcmp(PQcmdStatus(results), "RELEASE") == 0 ||
900900
strcmp(PQcmdStatus(results), "ROLLBACK") == 0)
901-
results = NULL;
901+
svptres = NULL;
902902
else
903-
results = PQexec(pset.db, "RELEASE pg_psql_temporary_savepoint");
903+
svptres = PQexec(pset.db, "RELEASE pg_psql_temporary_savepoint");
904904
}
905-
if (PQresultStatus(results) != PGRES_COMMAND_OK)
905+
if (svptres && PQresultStatus(svptres) != PGRES_COMMAND_OK)
906906
{
907907
psql_error("%s", PQerrorMessage(pset.db));
908908
PQclear(results);
909+
PQclear(svptres);
909910
ResetCancelConn();
910911
return false;
911912
}
912-
PQclear(results);
913913
}
914914

915+
PQclear(results);
916+
915917
/* Possible microtiming output */
916918
if (OK && pset.timing)
917919
printf(_("Time: %.3f ms\n"), DIFF_MSEC(&after, &before));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy