From: Sebastian Harl Date: Fri, 13 Dec 2013 13:29:42 +0000 (+0100) Subject: dbi utils: Don't keep invalid object address after closing DBI connections. X-Git-Tag: sysdb-0.1.0~300^2~13 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=808d0db2246e425485c0954c287509208dcc7f95;p=sysdb.git dbi utils: Don't keep invalid object address after closing DBI connections. --- diff --git a/src/utils/dbi.c b/src/utils/dbi.c index 2692618..d9bd369 100644 --- a/src/utils/dbi.c +++ b/src/utils/dbi.c @@ -284,8 +284,10 @@ sdb_dbi_client_connect(sdb_dbi_client_t *client) if ((! client) || (! client->driver) || (! client->database)) return -1; - if (client->conn) + if (client->conn) { dbi_conn_close(client->conn); + client->conn = NULL; + } driver = dbi_driver_open(client->driver); if (! driver) { @@ -332,6 +334,7 @@ sdb_dbi_client_connect(sdb_dbi_client_t *client) sdb_error_log(SDB_LOG_ERR); dbi_conn_close(client->conn); + client->conn = NULL; return -1; } } @@ -340,6 +343,7 @@ sdb_dbi_client_connect(sdb_dbi_client_t *client) sdb_log(SDB_LOG_ERR, "dbi: failed to set option 'dbname': %s", sdb_dbi_strerror(client->conn)); dbi_conn_close(client->conn); + client->conn = NULL; return -1; } @@ -347,6 +351,7 @@ sdb_dbi_client_connect(sdb_dbi_client_t *client) sdb_log(SDB_LOG_ERR, "dbi: failed to connect to database '%s': %s", client->database, sdb_dbi_strerror(client->conn)); dbi_conn_close(client->conn); + client->conn = NULL; return -1; } return 0; @@ -467,6 +472,7 @@ sdb_dbi_client_destroy(sdb_dbi_client_t *client) if (client->conn) dbi_conn_close(client->conn); + client->conn = NULL; if (client->options) sdb_dbi_options_destroy(client->options);