[Asterisk-code-review] res_rtp_asterisk: Free payload when error on insertion to data buffer (asterisk[17])

Friendly Automation asteriskteam at digium.com
Wed Apr 15 14:01:05 CDT 2020


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14238 )

Change subject: res_rtp_asterisk: Free payload when error on insertion to data buffer
......................................................................

res_rtp_asterisk: Free payload when error on insertion to data buffer

When the ast_data_buffer_put rejects to add a packet, for example because
the buffer already contains a packet with the same sequence number, the
payload will never be freed, resulting in a memory leak.

The data buffer will now return an error if this situation occurs
allowing the caller to free the payload. The res_rtp_asterisk module
has also been updated to do this.

ASTERISK-28826

Change-Id: Ie6c49495d1c921d5f997651c7d0f79646f095cf1
---
M main/data_buffer.c
M res/res_rtp_asterisk.c
2 files changed, 7 insertions(+), 3 deletions(-)

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



diff --git a/main/data_buffer.c b/main/data_buffer.c
index cfc323c..85e7971 100644
--- a/main/data_buffer.c
+++ b/main/data_buffer.c
@@ -254,7 +254,7 @@
 	AST_LIST_TRAVERSE_SAFE_END;
 
 	if (inserted == -1) {
-		return 0;
+		return -1;
 	}
 
 	if (!inserted) {
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index 4fc4217..5dd5d35 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -4991,7 +4991,9 @@
 			if (payload) {
 				payload->size = packet_len;
 				memcpy(payload->buf, rtpheader, packet_len);
-				ast_data_buffer_put(rtp->send_buffer, rtp->seqno, payload);
+				if (ast_data_buffer_put(rtp->send_buffer, rtp->seqno, payload) == -1) {
+					ast_free(payload);
+				}
 			}
 		}
 
@@ -7938,7 +7940,9 @@
 
 		payload->size = res;
 		memcpy(payload->buf, rtpheader, res);
-		ast_data_buffer_put(rtp->recv_buffer, seqno, payload);
+		if (ast_data_buffer_put(rtp->recv_buffer, seqno, payload) == -1) {
+			ast_free(payload);
+		}
 
 		/* If this sequence number is removed that means we had a gap and this packet has filled it in
 		 * some. Since it was part of the gap we will have already added any other missing sequence numbers

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

Gerrit-Project: asterisk
Gerrit-Branch: 17
Gerrit-Change-Id: Ie6c49495d1c921d5f997651c7d0f79646f095cf1
Gerrit-Change-Number: 14238
Gerrit-PatchSet: 2
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: nappsoft <infos at nappsoft.ch>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200415/5b872ebc/attachment.html>


More information about the asterisk-code-review mailing list