From 7ca4e21c15b151f35717ab8d8c59a521f9a6cb7b Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 19 Jul 2016 10:50:43 +0200 Subject: [PATCH] auth: Don't try to deallocate empty PG statements When a SPgSQLStatement is released without having been prepared, we execute an invalid 'DEALLOCATE ' SQL command. This might happen if the statement has not been used before being destroyed, for example. --- modules/gpgsqlbackend/spgsql.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/gpgsqlbackend/spgsql.cc b/modules/gpgsqlbackend/spgsql.cc index 78393ed1e0..7e4ef69dd2 100644 --- a/modules/gpgsqlbackend/spgsql.cc +++ b/modules/gpgsqlbackend/spgsql.cc @@ -184,9 +184,12 @@ private: void releaseStatement() { d_prepared = false; reset(); - string cmd = string("DEALLOCATE " + d_stmt); - PGresult *res = PQexec(d_db(), cmd.c_str()); - PQclear(res); + if (!d_stmt.empty()) { + string cmd = string("DEALLOCATE " + d_stmt); + PGresult *res = PQexec(d_db(), cmd.c_str()); + PQclear(res); + d_stmt.clear(); + } } void prepareStatement() { -- 2.47.2