Skip to content

Commit

Permalink
Fix sqlops memory leak in sql_avp_load / sql_avp_delete / sql_avp_store
Browse files Browse the repository at this point in the history
  • Loading branch information
nikbyte committed Feb 10, 2025
1 parent e8c94f9 commit 88808b6
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions modules/sqlops/sqlops.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ static int fixup_pvname_list(void** param);
static int fixup_avpname_list(void** param);

static int fixup_free_pvname_list(void** param);
static int fixup_free_avp_source(void** param);
static int fixup_free_avp_dbparam(void** param);

static int w_sql_avp_load(struct sip_msg* msg, void* source,
Expand Down Expand Up @@ -136,7 +137,7 @@ static const cmd_export_t cmds[] = {

{"sql_avp_load", (cmd_function)w_sql_avp_load, {
{CMD_PARAM_STR|CMD_PARAM_NO_EXPAND,
fixup_sql_avp_source, fixup_free_pkg},
fixup_sql_avp_source, fixup_free_avp_source},
{CMD_PARAM_STR|CMD_PARAM_NO_EXPAND,
fixup_sql_avp_dbparam_scheme, fixup_free_avp_dbparam},
{CMD_PARAM_INT|CMD_PARAM_OPT, fixup_db_url, 0},
Expand All @@ -146,7 +147,7 @@ static const cmd_export_t cmds[] = {

{"sql_avp_delete", (cmd_function)w_sql_avp_delete, {
{CMD_PARAM_STR|CMD_PARAM_NO_EXPAND,
fixup_sql_avp_source, fixup_free_pkg},
fixup_sql_avp_source, fixup_free_avp_source},
{CMD_PARAM_STR|CMD_PARAM_NO_EXPAND,
fixup_sql_avp_dbparam, fixup_free_avp_dbparam},
{CMD_PARAM_INT|CMD_PARAM_OPT, fixup_db_url, 0},
Expand All @@ -155,15 +156,14 @@ static const cmd_export_t cmds[] = {

{"sql_avp_store", (cmd_function)w_sql_avp_store, {
{CMD_PARAM_STR|CMD_PARAM_NO_EXPAND,
fixup_sql_avp_source, fixup_free_pkg},
fixup_sql_avp_source, fixup_free_avp_source},
{CMD_PARAM_STR|CMD_PARAM_NO_EXPAND,
fixup_sql_avp_dbparam, fixup_free_avp_dbparam},
{CMD_PARAM_INT|CMD_PARAM_OPT, fixup_db_url, 0},
{0, 0, 0}},
ALL_ROUTES},

{"sql_query", (cmd_function)w_sql_query, {
{CMD_PARAM_STR, 0, 0},
{CMD_PARAM_STR|CMD_PARAM_OPT|CMD_PARAM_NO_EXPAND,
fixup_avpname_list, fixup_free_pvname_list},
{CMD_PARAM_INT|CMD_PARAM_OPT,
Expand Down Expand Up @@ -544,6 +544,17 @@ static int fixup_sql_avp_dbparam(void** param)
return fixup_sql_avp(param, 2, 0);
}

static int fixup_free_avp_source(void** param)
{
struct fis_param* sp = (struct fis_param*)*param;

if ((sp->opd & SQLOPS_VAL_STR) && sp->u.s.s) {
pkg_free(sp->u.s.s);
}
pkg_free(sp);
return 0;
}

static int fixup_free_avp_dbparam(void** param)
{
struct db_param *dbp = (struct db_param *)*param;
Expand Down

0 comments on commit 88808b6

Please sign in to comment.