From: Florian Dold Date: Sat, 11 Feb 2017 15:41:58 +0000 (+0100) Subject: fix use-after-free in postgres error message X-Git-Tag: taler-0.2.1~187 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=de34229c6d0470a1f54aafffb778d72c2e5d9c39;p=oweals%2Fgnunet.git fix use-after-free in postgres error message --- 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; }