diff options
author | Richard Mudgett <rmudgett@digium.com> | 2012-01-27 18:47:16 +0000 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2012-01-27 18:47:16 +0000 |
commit | 27b69e7d29dc100e5fdf3cf911c3a02f3b5fd2b5 (patch) | |
tree | 7ad1cbac33a65eb9773db40058cabff69fe2eef1 /res | |
parent | 5bfea5fdbfca835b29e14ec9a28345c6095431b5 (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')
-rw-r--r-- | res/res_odbc.c | 5 | ||||
-rw-r--r-- | res/res_srtp.c | 46 | ||||
-rw-r--r-- | res/snmp/agent.c | 9 |
3 files changed, 36 insertions, 24 deletions
diff --git a/res/res_odbc.c b/res/res_odbc.c index 1770bb303..463bf9fdb 100644 --- a/res/res_odbc.c +++ b/res/res_odbc.c @@ -911,7 +911,7 @@ static int load_odbc_config(void) static char *handle_cli_odbc_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - struct ao2_iterator aoi = ao2_iterator_init(class_container, 0); + struct ao2_iterator aoi; struct odbc_class *class; struct odbc_obj *current; int length = 0; @@ -930,6 +930,7 @@ static char *handle_cli_odbc_show(struct ast_cli_entry *e, int cmd, struct ast_c if (a->pos != 2) return NULL; length = strlen(a->word); + aoi = ao2_iterator_init(class_container, 0); while ((class = ao2_iterator_next(&aoi))) { if (!strncasecmp(a->word, class->name, length) && ++which > a->n) { ret = ast_strdup(class->name); @@ -1722,12 +1723,14 @@ static int data_odbc_provider_handler(const struct ast_data_search *search, ao2_ref(current, -1); } + ao2_iterator_destroy(&aoi2); ao2_ref(class, -1); if (!ast_data_search_match(search, data_odbc_class)) { ast_data_remove_node(root, data_odbc_class); } } + ao2_iterator_destroy(&aoi); return 0; } 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); } diff --git a/res/snmp/agent.c b/res/snmp/agent.c index 153106e0d..71f02134f 100644 --- a/res/snmp/agent.c +++ b/res/snmp/agent.c @@ -703,6 +703,7 @@ static u_char *ast_var_indications(struct variable *vp, oid *name, size_t *lengt tz = ast_tone_zone_unref(tz); long_ret++; } + ao2_iterator_destroy(&i); return (u_char *) &long_ret; } @@ -743,6 +744,7 @@ static u_char *ast_var_indications_table(struct variable *vp, oid *name, size_t tz = ast_tone_zone_unref(tz); i--; } + ao2_iterator_destroy(&iter); if (tz == NULL) { return NULL; @@ -750,24 +752,27 @@ static u_char *ast_var_indications_table(struct variable *vp, oid *name, size_t switch (vp->magic) { case ASTINDINDEX: + ast_tone_zone_unref(tz); long_ret = name[*length - 1]; return (u_char *)&long_ret; case ASTINDCOUNTRY: ast_copy_string(ret_buf, tz->country, sizeof(ret_buf)); - tz = ast_tone_zone_unref(tz); + ast_tone_zone_unref(tz); *var_len = strlen(ret_buf); return (u_char *) ret_buf; case ASTINDALIAS: /* No longer exists */ + ast_tone_zone_unref(tz); return NULL; case ASTINDDESCRIPTION: ast_tone_zone_lock(tz); ast_copy_string(ret_buf, tz->description, sizeof(ret_buf)); ast_tone_zone_unlock(tz); - tz = ast_tone_zone_unref(tz); + ast_tone_zone_unref(tz); *var_len = strlen(ret_buf); return (u_char *) ret_buf; default: + ast_tone_zone_unref(tz); break; } return NULL; |