diff options
author | jrose <jrose@f38db490-d61c-443f-a65b-d21fe96a405b> | 2011-06-15 16:19:38 +0000 |
---|---|---|
committer | jrose <jrose@f38db490-d61c-443f-a65b-d21fe96a405b> | 2011-06-15 16:19:38 +0000 |
commit | 2964f0b2162c32cb18bd8deb2743cdc5952c4d06 (patch) | |
tree | b5ef894d6ddf88172d18b3c46d5f34e10ae54e40 /res | |
parent | 971343fd3c44eee5e0edf6d25dce34ac5fc6c097 (diff) |
Merged revisions 323610 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
........
r323610 | jrose | 2011-06-15 11:09:24 -0500 (Wed, 15 Jun 2011) | 7 lines
Adds PQclear calls on result to various parts of res_conf_pgsql
(closes issue ASTERISK-17812)
Reported by: byronclark
Patches:
pgsql_pqclear.patch uploaded by byronclark (license 1200)
........
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@323621 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r-- | res/res_config_pgsql.c | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c index caafb52df..bbc683a47 100644 --- a/res/res_config_pgsql.c +++ b/res/res_config_pgsql.c @@ -345,6 +345,7 @@ static struct tables *find_table(const char *database, const char *orig_tablenam if (!(table = ast_calloc(1, sizeof(*table) + strlen(orig_tablename) + 1))) { ast_log(LOG_ERROR, "Unable to allocate memory for new table structure\n"); + PQclear(result); AST_LIST_UNLOCK(&psql_tables); return NULL; } @@ -363,6 +364,7 @@ static struct tables *find_table(const char *database, const char *orig_tablenam if (!(column = ast_calloc(1, sizeof(*column) + strlen(fname) + strlen(ftype) + 2))) { ast_log(LOG_ERROR, "Unable to allocate column element for %s, %s\n", orig_tablename, fname); + PQclear(result); destroy_table(table); AST_LIST_UNLOCK(&psql_tables); return NULL; @@ -479,6 +481,7 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab ast_mutex_lock(&pgsql_lock); if (pgsql_exec(database, tablename, ast_str_buffer(sql), &result) != 0) { + PQclear(result); ast_mutex_unlock(&pgsql_lock); return NULL; } @@ -494,8 +497,8 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab ast_debug(1, "PostgreSQL RealTime: Found %d rows.\n", num_rows); if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) { - ast_mutex_unlock(&pgsql_lock); PQclear(result); + ast_mutex_unlock(&pgsql_lock); return NULL; } for (i = 0; i < numFields; i++) @@ -523,8 +526,8 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab ast_debug(1, "Postgresql RealTime: Could not find any rows in table %s@%s.\n", tablename, database); } - ast_mutex_unlock(&pgsql_lock); PQclear(result); + ast_mutex_unlock(&pgsql_lock); return var; } @@ -614,8 +617,22 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char if (pgsql_exec(database, table, ast_str_buffer(sql), &result) != 0) { ast_mutex_unlock(&pgsql_lock); - return NULL; - } + return NULL; + } else { + ExecStatusType result_status = PQresultStatus(result); + if (result_status != PGRES_COMMAND_OK + && result_status != PGRES_TUPLES_OK + && result_status != PGRES_NONFATAL_ERROR) { + ast_log(LOG_WARNING, + "PostgreSQL RealTime: Failed to query %s@%s. Check debug for more info.\n", table, database); + ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql)); + ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s (%s)\n", + PQresultErrorMessage(result), PQresStatus(result_status)); + PQclear(result); + ast_mutex_unlock(&pgsql_lock); + return NULL; + } + } ast_debug(1, "PostgreSQL RealTime: Result=%p Query: %s\n", result, ast_str_buffer(sql)); @@ -628,8 +645,8 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char ast_debug(1, "PostgreSQL RealTime: Found %d rows.\n", num_rows); if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) { - ast_mutex_unlock(&pgsql_lock); PQclear(result); + ast_mutex_unlock(&pgsql_lock); return NULL; } for (i = 0; i < numFields; i++) @@ -659,8 +676,8 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char ast_debug(1, "PostgreSQL RealTime: Could not find any rows in table %s.\n", table); } - ast_mutex_unlock(&pgsql_lock); PQclear(result); + ast_mutex_unlock(&pgsql_lock); return cfg; } @@ -763,6 +780,20 @@ static int update_pgsql(const char *database, const char *tablename, const char if (pgsql_exec(database, tablename, ast_str_buffer(sql), &result) != 0) { ast_mutex_unlock(&pgsql_lock); return -1; + } else { + ExecStatusType result_status = PQresultStatus(result); + if (result_status != PGRES_COMMAND_OK + && result_status != PGRES_TUPLES_OK + && result_status != PGRES_NONFATAL_ERROR) { + ast_log(LOG_WARNING, + "PostgreSQL RealTime: Failed to query database. Check debug for more info.\n"); + ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql)); + ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s (%s)\n", + PQresultErrorMessage(result), PQresStatus(result_status)); + PQclear(result); + ast_mutex_unlock(&pgsql_lock); + return -1; + } } numrows = atoi(PQcmdTuples(result)); @@ -950,6 +981,7 @@ static int store_pgsql(const char *database, const char *table, va_list ap) } insertid = PQoidValue(result); + PQclear(result); ast_mutex_unlock(&pgsql_lock); ast_debug(1, "PostgreSQL RealTime: row inserted on table: %s, id: %u\n", table, insertid); |