From: Remi Gacogne Date: Tue, 19 Jul 2016 08:50:43 +0000 (+0200) Subject: auth: Don't try to deallocate empty PG statements X-Git-Tag: auth-4.0.1~16^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ca4e21c15b151f35717ab8d8c59a521f9a6cb7b;p=pdns 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. --- diff --git a/modules/gpgsqlbackend/spgsql.cc b/modules/gpgsqlbackend/spgsql.cc index 78393ed1e..7e4ef69dd 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() {