[asterisk-commits] jrose: branch 1.8 r323610 - /branches/1.8/res/res_config_pgsql.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jun 15 11:09:31 CDT 2011


Author: jrose
Date: Wed Jun 15 11:09:24 2011
New Revision: 323610

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=323610
Log:
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:
    branches/1.8/res/res_config_pgsql.c

Modified: branches/1.8/res/res_config_pgsql.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/res/res_config_pgsql.c?view=diff&rev=323610&r1=323609&r2=323610
==============================================================================
--- branches/1.8/res/res_config_pgsql.c (original)
+++ branches/1.8/res/res_config_pgsql.c Wed Jun 15 11:09:24 2011
@@ -221,6 +221,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;
 	}
@@ -239,6 +240,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;
@@ -363,6 +365,7 @@
 				"PostgreSQL RealTime: Failed to query '%s@%s'. Check debug for more info.\n", tablename, database);
 		ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
 		ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
+		PQclear(result);
 		ast_mutex_unlock(&pgsql_lock);
 		return NULL;
 	} else {
@@ -391,8 +394,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++)
@@ -420,8 +423,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;
 }
@@ -530,6 +533,7 @@
 			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;
 		}
@@ -546,8 +550,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++)
@@ -577,8 +581,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;
 }
@@ -699,6 +703,7 @@
 			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;
 		}
@@ -929,6 +934,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