Skip to content

Commit

Permalink
topos: free empty db results
Browse files Browse the repository at this point in the history
- root structure and column names are allocated and lead to leak
- reported by Sergey Basov

(cherry picked from commit 3e1b30e)
  • Loading branch information
miconda committed Apr 21, 2017
1 parent ebc29b2 commit fdb4538
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/modules/topos/tps_storage.c
Expand Up @@ -810,6 +810,7 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
int nr_keys;
int nr_cols;
int n;
int ret = 0;

if(msg==NULL || md==NULL || sd==NULL || _tps_db_handle==NULL)
return -1;
Expand Down Expand Up @@ -853,7 +854,8 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
if (RES_ROW_N(db_res) <= 0) {
LM_DBG("no stored record for <%.*s>\n",
md->x_vbranch1.len, ZSW(md->x_vbranch1.s));
return 1;
ret = 1;
goto done;
}

sd->cp = sd->cbuf;
Expand All @@ -874,10 +876,11 @@ int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_method); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_cseq); n++;

done:
if ((db_res!=NULL) && _tpsdbf.free_result(_tps_db_handle, db_res)<0)
LM_ERR("failed to free result of query\n");

return 0;
return ret;

error:
if ((db_res!=NULL) && _tpsdbf.free_result(_tps_db_handle, db_res)<0)
Expand Down Expand Up @@ -907,6 +910,7 @@ int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
int nr_keys;
int nr_cols;
int n;
int ret = 0;

if(msg==NULL || md==NULL || sd==NULL || _tps_db_handle==NULL)
return -1;
Expand Down Expand Up @@ -983,7 +987,8 @@ int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
if (RES_ROW_N(db_res) <= 0) {
LM_DBG("no stored record for <%.*s>\n",
md->a_uuid.len, ZSW(md->a_uuid.s));
return 1;
ret = 1;
goto done;
}

sd->cp = sd->cbuf;
Expand Down Expand Up @@ -1011,10 +1016,11 @@ int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_method); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_cseq); n++;

done:
if ((db_res!=NULL) && _tpsdbf.free_result(_tps_db_handle, db_res)<0)
LM_ERR("failed to free result of query\n");

return 0;
return ret;

error:
if ((db_res!=NULL) && _tpsdbf.free_result(_tps_db_handle, db_res)<0)
Expand Down

0 comments on commit fdb4538

Please sign in to comment.