Skip to content

Commit

Permalink
Fix iteration on the reports of an identifier
Browse files Browse the repository at this point in the history
Proper test the overflow condition (this was generating some shm mem leak)
Proper iteration for printing the reports after the buffer overflows

(cherry picked from commit f8ee4c7)
  • Loading branch information
bogdan-iancu committed Aug 24, 2022
1 parent 0b51141 commit c1ee52a
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions status_report.c
Expand Up @@ -577,20 +577,21 @@ int sr_add_report(void *group,
} else {
idx = (sri->last_report+1) % sri->max_reports;
}
sri->last_report = idx;

LM_DBG("adding report to identifier [%.*s] group [%.*s] on idx %d "
"[%d,%d]\n", identifier.len, identifier.s,
srg->name.len, srg->name.s, idx, sri->first_report, sri->last_report);

if (idx==sri->first_report && sri->first_report!=sri->last_report) {
if (idx==sri->first_report && -1!=sri->last_report) {
/* overflow, free the oldest report */
shm_free( sri->reports[idx].log.s );
sri->reports[idx].log.s = NULL;
sri->reports[idx].log.len = 0;
sri->first_report = (sri->first_report+1) % sri->max_reports;
}

sri->last_report = idx;

LM_DBG("adding report to identifier [%.*s] group [%.*s] on idx %d "
"[%d,%d]\n", identifier.len, identifier.s,
srg->name.len, srg->name.s, idx, sri->first_report, sri->last_report);

/* copy the report here */
sri->reports[idx].log.s = s;
memcpy( s, report_s, report_len);
Expand Down Expand Up @@ -943,7 +944,7 @@ mi_response_t *mi_sr_list_status(const mi_params_t *params,
static int _mi_list_reports(sr_identifier *sri, mi_item_t *log_arr)
{
mi_item_t *log_item;
short i, end;
short i, cnt;
str date;

lock_get( &sri->lock );
Expand All @@ -954,12 +955,15 @@ static int _mi_list_reports(sr_identifier *sri, mi_item_t *log_arr)
return 0;
}

end = (sri->last_report+1) % sri->max_reports;

LM_DBG("idxes: first=%d, last=%d, end=%d\n",
sri->first_report,sri->last_report,end);
cnt = sri->last_report - sri->first_report + 1;
if (cnt<=0)
cnt += sri->max_reports;

LM_DBG("idxes: first=%d, last=%d, cnt=%d\n",
sri->first_report,sri->last_report,cnt);

for ( i=sri->first_report ; i!=end ; i=(i+1)%sri->max_reports ) {
for ( i=sri->first_report ; cnt ; i=(i+1)%sri->max_reports,cnt-- ) {

log_item = add_mi_object( log_arr, 0, 0);
if (log_item==NULL)
Expand Down

0 comments on commit c1ee52a

Please sign in to comment.