From de34229c6d0470a1f54aafffb778d72c2e5d9c39 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 11 Feb 2017 16:41:58 +0100 Subject: [PATCH] fix use-after-free in postgres error message --- src/postgres/postgres.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/postgres/postgres.c b/src/postgres/postgres.c index 4798c129d..14095c5a4 100644 --- a/src/postgres/postgres.c +++ b/src/postgres/postgres.c @@ -182,22 +182,22 @@ GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle * cfg, &conninfo)) conninfo = NULL; dbh = PQconnectdb (conninfo == NULL ? "" : conninfo); - GNUNET_free_non_null (conninfo); - if (NULL == dbh) - { - /* FIXME: warn about out-of-memory? */ - return NULL; - } - if (PQstatus (dbh) != CONNECTION_OK) + + if (NULL != dbh) { - GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, - "postgres", - _("Unable to connect to Postgres database '%s': %s\n"), - conninfo, - PQerrorMessage (dbh)); - PQfinish (dbh); - return NULL; + if (PQstatus (dbh) != CONNECTION_OK) + { + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, + "postgres", + _("Unable to connect to Postgres database '%s': %s\n"), + conninfo, + PQerrorMessage (dbh)); + PQfinish (dbh); + dbh = NULL; + } } + // FIXME: warn about out-of-memory when dbh is NULL? + GNUNET_free_non_null (conninfo); return dbh; } -- 2.25.1