From 4b99ab1d2b0d8ec288935aaf8deaa818f6f5a84e Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 27 Jun 2022 14:40:58 -0400 Subject: [PATCH] TT#182200 fix CDR index bookkeeping The `cdr_index` variable already tracks the number of created CDRs, as it points to the slot for the next CDR record to be inserted. It's increased by one at the start of the processing loop, so if we end up skipping over an entry after it's been increased, it must be decreased again, which keeps the count intact and prevents empty CDR records from being created. Fix-up for Ia7e8446fe4953d1391f99ea1530990e3d385c056 Change-Id: Ibb650a4b00978a272ef8f60751f6efda0491a912 --- cdr.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cdr.c b/cdr.c index 36198b9..f71572d 100644 --- a/cdr.c +++ b/cdr.c @@ -1412,7 +1412,7 @@ static cdr_entry_t *alloc_cdrs(uint64_t cdr_count) { static int cdr_create_cdrs(GQueue *records, cdr_entry_t **cdrs, uint64_t *cdr_count, uint64_t *alloc_size, uint8_t *trash, int do_intermediate) { - uint64_t i = 0, cdr_index = 0, created = 0; + uint64_t i = 0, cdr_index = 0; uint64_t invites = 0; int timed_out = 0; @@ -1506,6 +1506,7 @@ static int cdr_create_cdrs(GQueue *records, if (validate_src_dst_leg(e)) { L_DEBUG("Skip intermediate CDR index %lu without valid src_leg and dst_leg for call-id '%s'\n", cdr_index, e->callid); + cdr_index--; continue; } @@ -1518,8 +1519,6 @@ static int cdr_create_cdrs(GQueue *records, } } - ++created; // TODO: move to the end when everything is successful ? - g_string_assign(cdr->call_id, e->callid); cdr->start_time = e->unix_timestamp; cdr->duration = (tmp_unix_endtime >= e->unix_timestamp) ? tmp_unix_endtime - e->unix_timestamp : 0; @@ -1561,7 +1560,7 @@ static int cdr_create_cdrs(GQueue *records, return -1; } - *cdr_count = created; + *cdr_count = cdr_index; /*L_DEBUG("Created %llu CDRs:", *cdr_count);*/