diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c index b4398e8..c22e5af 100644 --- a/res/res_config_pgsql.c +++ b/res/res_config_pgsql.c @@ -221,6 +221,7 @@ static struct tables *find_table(const char *orig_tablename) 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; } @@ -240,6 +241,7 @@ static struct tables *find_table(const char *orig_tablename) 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); destroy_table(table); + PQclear(result); AST_LIST_UNLOCK(&psql_tables); return NULL; } @@ -375,6 +377,7 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab 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; } @@ -391,8 +394,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++) @@ -420,8 +423,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; } @@ -530,6 +533,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char 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 @@ 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++) @@ -577,8 +581,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; } @@ -699,12 +703,14 @@ static int update_pgsql(const char *database, const char *tablename, const char 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)); + PQclear(result); ast_mutex_unlock(&pgsql_lock); ast_debug(1, "PostgreSQL RealTime: Updated %d rows on table: %s\n", numrows, tablename); @@ -830,12 +836,14 @@ static int update2_pgsql(const char *database, const char *tablename, va_list ap 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)); + PQclear(result); ast_mutex_unlock(&pgsql_lock); ast_debug(1, "PostgreSQL RealTime: Updated %d rows on table: %s\n", numrows, tablename); @@ -923,12 +931,14 @@ static int store_pgsql(const char *database, const char *table, va_list ap) ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql1)); 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; } } 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);