summaryrefslogtreecommitdiff
path: root/res/res_srtp.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2012-01-27 18:47:16 +0000
committerRichard Mudgett <rmudgett@digium.com>2012-01-27 18:47:16 +0000
commit27b69e7d29dc100e5fdf3cf911c3a02f3b5fd2b5 (patch)
tree7ad1cbac33a65eb9773db40058cabff69fe2eef1 /res/res_srtp.c
parent5bfea5fdbfca835b29e14ec9a28345c6095431b5 (diff)
Audit of ao2_iterator_init() usage for v1.8.
Fixes numerous reference leaks and missing ao2_iterator_destroy() calls as a result. Review: https://reviewboard.asterisk.org/r/1697/ ........ Merged revisions 352955 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 352956 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@352957 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_srtp.c')
-rw-r--r--res/res_srtp.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/res/res_srtp.c b/res/res_srtp.c
index a232314fa..a22a02089 100644
--- a/res/res_srtp.c
+++ b/res/res_srtp.c
@@ -322,7 +322,7 @@ static int ast_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len, int rt
int retry = 0;
struct ast_rtp_instance_stats stats = {0,};
- tryagain:
+tryagain:
for (i = 0; i < 2; i++) {
res = rtcp ? srtp_unprotect_rtcp(srtp->session, buf, len) : srtp_unprotect(srtp->session, buf, len);
@@ -348,38 +348,42 @@ static int ast_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len, int rt
if (srtp->session) {
struct ast_srtp_policy *policy;
struct ao2_iterator it;
- int policies_count = 0;
-
+ int policies_count;
+
// dealloc first
ast_log(LOG_WARNING, "SRTP destroy before re-create\n");
srtp_dealloc(srtp->session);
-
+
// get the count
policies_count = ao2_container_count(srtp->policies);
-
+
// get the first to build up
it = ao2_iterator_init(srtp->policies, 0);
policy = ao2_iterator_next(&it);
ast_log(LOG_WARNING, "SRTP try to re-create\n");
- if (srtp_create(&srtp->session, &policy->sp) == err_status_ok) {
- ast_log(LOG_WARNING, "SRTP re-created with first policy\n");
-
- // unref first element
- ao2_t_ref(policy, -1, "Unreffing first policy for re-creating srtp session");
-
- // if we have more than one policy, add them afterwards
- if (policies_count > 1) {
- ast_log(LOG_WARNING, "Add all the other %d policies\n", policies_count-1);
- while ((policy = ao2_iterator_next(&it))) {
- srtp_add_stream(srtp->session, &policy->sp);
- ao2_t_ref(policy, -1, "Unreffing n-th policy for re-creating srtp session");
+ if (policy) {
+ if (srtp_create(&srtp->session, &policy->sp) == err_status_ok) {
+ ast_log(LOG_WARNING, "SRTP re-created with first policy\n");
+
+ // unref first element
+ ao2_t_ref(policy, -1, "Unreffing first policy for re-creating srtp session");
+
+ // if we have more than one policy, add them afterwards
+ if (policies_count > 1) {
+ ast_log(LOG_WARNING, "Add all the other %d policies\n",
+ policies_count - 1);
+ while ((policy = ao2_iterator_next(&it))) {
+ srtp_add_stream(srtp->session, &policy->sp);
+ ao2_t_ref(policy, -1, "Unreffing n-th policy for re-creating srtp session");
+ }
}
+
+ retry++;
+ ao2_iterator_destroy(&it);
+ goto tryagain;
}
-
- retry++;
- ao2_iterator_destroy(&it);
- goto tryagain;
+ ao2_t_ref(policy, -1, "Unreffing first policy after srtp_create failed");
}
ao2_iterator_destroy(&it);
}