[Asterisk-code-review] cdr.c: Fix runtime leak of CDR records. (asterisk[13])

Jenkins2 asteriskteam at digium.com
Mon Feb 12 09:35:31 CST 2018


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/8175 )

Change subject: cdr.c: Fix runtime leak of CDR records.
......................................................................

cdr.c: Fix runtime leak of CDR records.

Need to remove all CDR's listed by a CDR object from the active_cdrs_all
container including the root/master record.

ASTERISK-27656

Change-Id: I48b4970663fea98baa262593d2204ef304aaf80e
---
M main/cdr.c
1 file changed, 10 insertions(+), 2 deletions(-)

Approvals:
  Corey Farrell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/main/cdr.c b/main/cdr.c
index 90371a4..3e02c3e 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -371,7 +371,7 @@
 /*! \brief A container of the active master CDRs indexed by Party A channel uniqueid */
 static struct ao2_container *active_cdrs_master;
 
-/*! \brief A container of all active CDRs indexed by Party B channel name */
+/*! \brief A container of all active CDRs with a Party B indexed by Party B channel name */
 static struct ao2_container *active_cdrs_all;
 
 /*! \brief Message router for stasis messages regarding channel state */
@@ -971,13 +971,21 @@
 
 	ast_assert(cdr->is_root);
 
+	/* Hold a ref to the root CDR to ensure the list members don't go away on us. */
+	ao2_ref(cdr, +1);
 	ao2_lock(active_cdrs_all);
-	for (cur = cdr->next; cur; cur = next) {
+	for (cur = cdr; cur; cur = next) {
 		next = cur->next;
 		ao2_unlink_flags(active_cdrs_all, cur, OBJ_NOLOCK);
+		/*
+		 * It is safe to still use cur after unlinking because the
+		 * root CDR holds a ref to all the CDRs in the list and we
+		 * have a ref to the root CDR.
+		 */
 		ast_string_field_set(cur, party_b_name, "");
 	}
 	ao2_unlock(active_cdrs_all);
+	ao2_ref(cdr, -1);
 }
 
 /*!

-- 
To view, visit https://gerrit.asterisk.org/8175
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I48b4970663fea98baa262593d2204ef304aaf80e
Gerrit-Change-Number: 8175
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180212/a0396b71/attachment.html>


More information about the asterisk-code-review mailing list