[Asterisk-code-review] rtp engine: Prevent unnecessary memory increases during calls. (asterisk[11])
Mark Michelson
asteriskteam at digium.com
Wed Apr 29 11:56:39 CDT 2015
Mark Michelson has uploaded a new change for review.
https://gerrit.asterisk.org/291
Change subject: rtp_engine: Prevent unnecessary memory increases during calls.
......................................................................
rtp_engine: Prevent unnecessary memory increases during calls.
The doxygen for ast_rtp_codecs_payloads_copy() states:
"This copies the payloads from the codecs0 structure to the codecs1
structure, overwriting any current values."
However, in practice, the overwriting of current values was not
happening. Instead, a new RTP codec payload object would be appended to
the codecs1 structure instead of replacing the corresponding object.
This patch corrects this behavior by overwriting the object in the
codecs1 structure if it exists already. If it does not already exist,
then create a new copy and link it in.
Tests of "memory show summary rtp_engine.c" had previously shown
additional allocations being performed any time that Asterisk processed
an incoming SDP. Scenarios involving lots of reinvites resulted in lots
of allocations. With this patch, I can perform as many reinvites as
I want and see no memory increases from the RTP engine.
ASTERISK-24916 #close
Reported by Christophe Osuna
Change-Id: I9a90bc3f564535bc767bf2fc0c455d5f065cea75
---
M main/rtp_engine.c
1 file changed, 11 insertions(+), 2 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/91/291/1
diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index 870ccc4..b16b5de 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -503,12 +503,19 @@
for (i = 0; i < AST_RTP_MAX_PT; i++) {
struct ast_rtp_payload_type *new_type;
+ int payload_alloced = 0;
if (!(type = ao2_find(src->payloads, &i, OBJ_KEY | OBJ_NOLOCK))) {
continue;
}
- if (!(new_type = ao2_alloc(sizeof(*new_type), NULL))) {
+ new_type = ao2_find(dest->payloads, &i, OBJ_KEY | OBJ_NOLOCK);
+ if (!new_type) {
+ new_type = ao2_alloc(sizeof(*new_type), NULL);
+ payload_alloced = 1;
+ }
+
+ if (!new_type) {
continue;
}
@@ -517,7 +524,9 @@
new_type->payload = i;
*new_type = *type;
- ao2_link_flags(dest->payloads, new_type, OBJ_NOLOCK);
+ if (payload_alloced) {
+ ao2_link_flags(dest->payloads, new_type, OBJ_NOLOCK);
+ }
ao2_ref(new_type, -1);
--
To view, visit https://gerrit.asterisk.org/291
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9a90bc3f564535bc767bf2fc0c455d5f065cea75
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 11
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>
More information about the asterisk-code-review
mailing list