[asterisk-commits] jrose: trunk r323621 - in /trunk: ./ res/res_config_pgsql.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jun 15 11:19:50 CDT 2011
Author: jrose
Date: Wed Jun 15 11:19:38 2011
New Revision: 323621
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=323621
Log:
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)
........
Modified:
trunk/ (props changed)
trunk/res/res_config_pgsql.c
Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Modified: trunk/res/res_config_pgsql.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_config_pgsql.c?view=diff&rev=323621&r1=323620&r2=323621
==============================================================================
--- trunk/res/res_config_pgsql.c (original)
+++ trunk/res/res_config_pgsql.c Wed Jun 15 11:19:38 2011
@@ -345,6 +345,7 @@
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 @@
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 @@
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 @@
ast_debug(1, "PostgreSQL RealTime: Found %d rows.\n", num_rows);
if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
+ PQclear(result);
ast_mutex_unlock(&pgsql_lock);
- PQclear(result);
return NULL;
}
for (i = 0; i < numFields; i++)
@@ -523,8 +526,8 @@
ast_debug(1, "Postgresql RealTime: Could not find any rows in table %s@%s.\n", tablename, database);
}
+ PQclear(result);
ast_mutex_unlock(&pgsql_lock);
- PQclear(result);
return var;
}
@@ -614,8 +617,22 @@
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 @@
ast_debug(1, "PostgreSQL RealTime: Found %d rows.\n", num_rows);
if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
+ PQclear(result);
ast_mutex_unlock(&pgsql_lock);
- PQclear(result);
return NULL;
}
for (i = 0; i < numFields; i++)
@@ -659,8 +676,8 @@
ast_debug(1, "PostgreSQL RealTime: Could not find any rows in table %s.\n", table);
}
+ PQclear(result);
ast_mutex_unlock(&pgsql_lock);
- PQclear(result);
return cfg;
}
@@ -763,6 +780,20 @@
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 @@
}
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);
More information about the asterisk-commits
mailing list