aboutsummaryrefslogtreecommitdiff
path: root/src/postgres/postgres.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-02-11 16:41:58 +0100
committerFlorian Dold <florian.dold@gmail.com>2017-02-11 16:41:58 +0100
commitde34229c6d0470a1f54aafffb778d72c2e5d9c39 (patch)
treef5170a88b384bcbc45b6f7118853ecffd6b0d152 /src/postgres/postgres.c
parentf1a91551990bc81e4179d48256bf14252bad7d0d (diff)
fix use-after-free in postgres error message
Diffstat (limited to 'src/postgres/postgres.c')
-rw-r--r--src/postgres/postgres.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/postgres/postgres.c b/src/postgres/postgres.c
index 4798c129d3..14095c5a44 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;
}