Fix a variety of memory leaks
[asterisk/asterisk.git] / res / res_srtp.c
index 9f9bf75..f651c40 100644 (file)
@@ -433,12 +433,14 @@ static int ast_srtp_create(struct ast_srtp **srtp, struct ast_rtp_instance *rtp,
        if (!(temp = res_srtp_new())) {
                return -1;
        }
+       ast_module_ref(ast_module_info->self);
 
+       /* Any failures after this point can use ast_srtp_destroy to destroy the instance */
        if (srtp_create(&temp->session, &policy->sp) != err_status_ok) {
+               ast_srtp_destroy(temp);
                return -1;
        }
 
-       ast_module_ref(ast_module_info->self);
        temp->rtp = rtp;
        *srtp = temp;
 
@@ -475,7 +477,7 @@ static int ast_srtp_add_stream(struct ast_srtp *srtp, struct ast_srtp_policy *po
        /* For existing streams, replace if its an SSRC stream, or bail if its a wildcard */
        if ((match = find_policy(srtp, &policy->sp, OBJ_POINTER))) {
                if (policy->sp.ssrc.type != ssrc_specific) {
-                       ast_log(AST_LOG_WARNING, "Cannot replace an existing wildcard policy");
+                       ast_log(AST_LOG_WARNING, "Cannot replace an existing wildcard policy\n");
                        ao2_t_ref(match, -1, "Unreffing already existing policy");
                        return -1;
                } else {
@@ -530,9 +532,6 @@ static int ast_srtp_change_source(struct ast_srtp *srtp, unsigned int from_ssrc,
 static void res_srtp_shutdown(void)
 {
        srtp_install_event_handler(NULL);
-       if (srtp_shutdown() != err_status_ok) {
-               ast_log(AST_LOG_WARNING, "Failed to de-initialize libsrtp\n");
-       }
        ast_rtp_engine_unregister_srtp();
        g_initialized = 0;
 }