Skip to content

Commit

Permalink
sql_cacher: fix a memory leak in case of a failed SQL query
Browse files Browse the repository at this point in the history
Reported by Ben Newlin in #1760

(cherry picked from commit aa38fb1)
  • Loading branch information
rvlad-patrascu committed Jul 11, 2019
1 parent ef29dce commit fddfe9f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/sql_cacher/sql_cacher.c
Expand Up @@ -766,26 +766,30 @@ static int load_entire_table(cache_entry_t *c_entry, db_handlers_t *db_hdls,
LM_ERR("Invalid table name: %.*s\n", c_entry->table.len, c_entry->table.s);
db_hdls->db_funcs.close(db_hdls->db_con);
db_hdls->db_con = 0;
pkg_free(query_cols);
return -1;
}
if (DB_CAPABILITY(db_hdls->db_funcs, DB_CAP_FETCH)) {
if (db_hdls->db_funcs.query(db_hdls->db_con, NULL, 0, NULL,
query_cols, 0, c_entry->nr_columns + 1, 0, 0) != 0) {
LM_ERR("Failure to issue query to SQL DB: %.*s\n",
c_entry->db_url.len, c_entry->db_url.s);
pkg_free(query_cols);
goto error;
}

if (db_hdls->db_funcs.fetch_result(db_hdls->db_con,&sql_res,fetch_nr_rows)<0) {
LM_ERR("Error fetching rows from SQL DB: %.*s\n",
c_entry->db_url.len, c_entry->db_url.s);
pkg_free(query_cols);
goto error;
}
} else {
if (db_hdls->db_funcs.query(db_hdls->db_con, NULL, 0, NULL,
query_cols, 0, c_entry->nr_columns + 1, 0, &sql_res) != 0) {
LM_ERR("Failure to issue query to SQL DB: %.*s\n",
c_entry->db_url.len, c_entry->db_url.s);
pkg_free(query_cols);
goto error;
}
}
Expand Down

0 comments on commit fddfe9f

Please sign in to comment.