Index: src/libs/zbxdb/db.c =================================================================== --- src/libs/zbxdb/db.c (revision 41871) +++ src/libs/zbxdb/db.c (working copy) @@ -359,6 +359,8 @@ { zabbix_errlog(ERR_Z3001, dbname, 0, PQerrorMessage(conn)); ret = ZBX_DB_DOWN; + + zbx_db_close(); } else { @@ -366,23 +368,23 @@ if (NULL != (row = DBfetch(result))) ZBX_PG_BYTEAOID = atoi(row[0]); DBfree_result(result); - } - ZBX_PG_SVERSION = PQserverVersion(conn); - zabbix_log(LOG_LEVEL_DEBUG, "PostgreSQL Server version: %d", ZBX_PG_SVERSION); + ZBX_PG_SVERSION = PQserverVersion(conn); + zabbix_log(LOG_LEVEL_DEBUG, "PostgreSQL Server version: %d", ZBX_PG_SVERSION); - /* disable "nonstandard use of \' in a string literal" warning */ - DBexecute("set escape_string_warning to off"); + /* disable "nonstandard use of \' in a string literal" warning */ + DBexecute("set escape_string_warning to off"); - result = DBselect("show standard_conforming_strings"); - if (NULL != (row = DBfetch(result))) - ZBX_PG_ESCAPE_BACKSLASH = (0 == strcmp(row[0], "off")); - DBfree_result(result); + result = DBselect("show standard_conforming_strings"); + if (NULL != (row = DBfetch(result))) + ZBX_PG_ESCAPE_BACKSLASH = (0 == strcmp(row[0], "off")); + DBfree_result(result); - if (90000 <= ZBX_PG_SVERSION) - { - /* change the output format for values of type bytea from hex (the default) to escape */ - DBexecute("set bytea_output=escape"); + if (90000 <= ZBX_PG_SVERSION) + { + /* change the output format for values of type bytea from hex (the default) to escape */ + DBexecute("set bytea_output=escape"); + } } #elif defined(HAVE_SQLITE3) #ifdef HAVE_FUNCTION_SQLITE3_OPEN_V2 @@ -512,8 +514,11 @@ oracle.srvhp = NULL; } #elif defined(HAVE_POSTGRESQL) - PQfinish(conn); - conn = NULL; + if (NULL != conn) + { + PQfinish(conn); + conn = NULL; + } #elif defined(HAVE_SQLITE3) sqlite3_close(conn); conn = NULL;