diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2006-06-30 15:06:16 +0000 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2006-06-30 15:06:16 +0000 |
commit | 55a39e0b0b2c74166c0faba7cd020166ab7ee4b6 (patch) | |
tree | d447fc21ff67e546be30275bbc91d6112ac24934 | |
parent | 60f46dee719d29dc82a2df2946c1e5b30ad95bc9 (diff) | |
download | postgresql-55a39e0b0b2c74166c0faba7cd020166ab7ee4b6.tar.gz |
Fix use-after-free error reported by Neil Conway.
-rw-r--r-- | src/bin/psql/common.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 80d4c91c00..0699bc0070 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.110.2.1 2005/11/22 18:23:27 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.110.2.2 2006/06/30 15:06:16 alvherre Exp $ */ #include "postgres_fe.h" #include "common.h" @@ -1067,19 +1067,19 @@ SendQuery(const char *query) if (OK) OK = PrintQueryResults(results); - PQclear(results); - /* If we made a temporary savepoint, possibly release/rollback */ if (on_error_rollback_savepoint) { + PGresult *svptres; + transaction_status = PQtransactionStatus(pset.db); /* We always rollback on an error */ if (transaction_status == PQTRANS_INERROR) - results = PQexec(pset.db, "ROLLBACK TO pg_psql_temporary_savepoint"); + svptres = PQexec(pset.db, "ROLLBACK TO pg_psql_temporary_savepoint"); /* If they are no longer in a transaction, then do nothing */ else if (transaction_status != PQTRANS_INTRANS) - results = NULL; + svptres = NULL; else { /* @@ -1090,20 +1090,22 @@ SendQuery(const char *query) if (strcmp(PQcmdStatus(results), "SAVEPOINT") == 0 || strcmp(PQcmdStatus(results), "RELEASE") == 0 || strcmp(PQcmdStatus(results), "ROLLBACK") == 0) - results = NULL; + svptres = NULL; else - results = PQexec(pset.db, "RELEASE pg_psql_temporary_savepoint"); + svptres = PQexec(pset.db, "RELEASE pg_psql_temporary_savepoint"); } - if (PQresultStatus(results) != PGRES_COMMAND_OK) + if (svptres && PQresultStatus(svptres) != PGRES_COMMAND_OK) { psql_error("%s", PQerrorMessage(pset.db)); PQclear(results); + PQclear(svptres); ResetCancelConn(); return false; } - PQclear(results); } + PQclear(results); + /* Possible microtiming output */ if (OK && pset.timing) printf(_("Time: %.3f ms\n"), DIFF_MSEC(&after, &before)); |