Skip to content

Commit

Permalink
Fix memory leak in using extra accounting.
Browse files Browse the repository at this point in the history
If setting $acc_extra() for a sequential request, before being matched against the dialog, the values will result in a leak.
Ideally, the acc_extra set in the processing context should be merged with the acc_extra fetched after dialog matching.

(cherry picked from commit 19305de)
  • Loading branch information
bogdan-iancu committed May 24, 2018
1 parent f8f46f1 commit 789b0e6
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions modules/acc/acc_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,22 @@ static inline void on_missed(struct cell *t, struct sip_msg *req,

}

static void acc_dlg_ctx_cb(struct dlg_cell *dlg, int type,
struct dlg_cb_params *_params)
{
acc_ctx_t *ctx;
/* set the acc context from dialog into the
* current processing context */

/* if there is already a acc context in the processing
* context, be sure to destroy it for now */
if ( (ctx=ACC_GET_CTX)!=NULL) {
free_acc_ctx(ctx);
}

ACC_PUT_CTX( (acc_ctx_t *)(*_params->param) );
}


/* restore callbacks */
void acc_loaded_callback(struct dlg_cell *dlg, int type,
Expand Down Expand Up @@ -735,6 +751,14 @@ void acc_loaded_callback(struct dlg_cell *dlg, int type,
LM_ERR("cannot register callback for database accounting\n");
return;
}

/* register dlg callbacks for ctx management */
if (dlg_api.register_dlgcb(dlg, DLGCB_REQ_WITHIN,
acc_dlg_ctx_cb, ctx, NULL) != 0) {
LM_ERR("cannot register callback ctx management\n");
return;
}

}

/* initiate a report if we previously enabled accounting for this t */
Expand Down Expand Up @@ -818,6 +842,14 @@ static inline void acc_onreply( struct cell* t, struct sip_msg *req,
LM_ERR("cannot register callback for database accounting\n");
goto restore;
}

/* register dlg callbacks for ctx management */
if (dlg_api.register_dlgcb(dlg, DLGCB_REQ_WITHIN,
acc_dlg_ctx_cb, ctx, NULL) != 0) {
LM_ERR("cannot register callback ctx management\n");
goto restore;
}

} else {
/* do old accounting */
if ( is_evi_acc_on(*flags) ) {
Expand Down Expand Up @@ -858,6 +890,12 @@ static void acc_dlg_callback(struct dlg_cell *dlg, int type,
return;
}

/* if there is already a acc context in the processing
* context, be sure to destroy it for now */
if ( (ctx=ACC_GET_CTX)!=NULL) {
free_acc_ctx(ctx);
}

ctx = *_params->param;
ACC_PUT_CTX(ctx);

Expand Down

0 comments on commit 789b0e6

Please sign in to comment.