[Asterisk-code-review] res_musiconhold.c: Plug ref leak caused by ao2_replace() misuse. (asterisk[16])

Joshua Colp asteriskteam at digium.com
Wed Mar 10 04:17:18 CST 2021


Joshua Colp has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15596 )

Change subject: res_musiconhold.c: Plug ref leak caused by ao2_replace() misuse.
......................................................................

res_musiconhold.c: Plug ref leak caused by ao2_replace() misuse.

ao2_replace() bumps the reference count of the object that is doing the
replacing, which is not what we want. We just want to drop the old ref
on the old object and update the pointer to point to the new object.

Pointed out by George Joseph in #asterisk-dev

Change-Id: Ie8167ed3d4b52b9d1ea2d785f885e8c27206743d
---
M res/res_musiconhold.c
1 file changed, 4 insertions(+), 2 deletions(-)

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



diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 736ddc6..9811ea7 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -1209,7 +1209,8 @@
 
 		/* We don't need to lock here because we are the thread that
 		 * created this mohclass and we haven't published it yet */
-		ao2_replace(mohclass->files, playlist_entries);
+		ao2_ref(mohclass->files, -1);
+		mohclass->files = playlist_entries;
 	}
 }
 
@@ -1306,7 +1307,8 @@
 	AST_VECTOR_COMPACT(files);
 
 	ao2_lock(class);
-	ao2_replace(class->files, files);
+	ao2_ref(class->files, -1);
+	class->files = files;
 	ao2_unlock(class);
 
 	return AST_VECTOR_SIZE(files);

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15596
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ie8167ed3d4b52b9d1ea2d785f885e8c27206743d
Gerrit-Change-Number: 15596
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210310/4600d2e3/attachment.html>


More information about the asterisk-code-review mailing list