]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
channel: Fix reference counting in ast_channel_suppress.
authorJoshua Colp <jcolp@digium.com>
Thu, 15 Jun 2017 12:32:32 +0000 (12:32 +0000)
committerJoshua Colp <jcolp@digium.com>
Thu, 15 Jun 2017 12:36:50 +0000 (07:36 -0500)
The ast_channel_suppress function wrongly decremented the
reference count of the underlying structure used to keep
track of what should be suppressed on a channel if the
function was called multiple times on the same channel.

This change cleans up the reference counting a bit so
this no longer occurs.

ASTERISK-27016

Change-Id: I2eed4077cb4916e6626f9f120b63b963acc5c136

main/channel.c

index a4e1dd537db85532bea7f23864eb3605573460df..371a89ffdd77d62059e86ecc32bcf5c82ba62771 100644 (file)
@@ -10862,7 +10862,7 @@ static const struct ast_datastore_info *suppress_get_datastore_information(enum
 
 int ast_channel_suppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
 {
-       RAII_VAR(struct suppress_data *, suppress, NULL, ao2_cleanup);
+       struct suppress_data *suppress;
        const struct ast_datastore_info *datastore_info = NULL;
        struct ast_datastore *datastore = NULL;
        struct ast_framehook_interface interface = {
@@ -10898,6 +10898,7 @@ int ast_channel_suppress(struct ast_channel *chan, unsigned int direction, enum
        if (framehook_id < 0) {
                /* Hook attach failed.  Get rid of the evidence. */
                ast_log(LOG_WARNING, "Failed to attach framehook while attempting to suppress a stream.\n");
+               ao2_ref(suppress, -1);
                return -1;
        }
 
@@ -10909,11 +10910,11 @@ int ast_channel_suppress(struct ast_channel *chan, unsigned int direction, enum
        if (!(datastore = ast_datastore_alloc(datastore_info, NULL))) {
                ast_log(LOG_WARNING, "Failed to allocate datastore while attempting to suppress a stream.\n");
                ast_framehook_detach(chan, framehook_id);
+               ao2_ref(suppress, -1);
                return -1;
        }
 
-       /* and another ref for the datastore */
-       ao2_ref(suppress, +1);
+       /* the ref provided by the allocation is taken by the datastore */
        datastore->data = suppress;
 
        ast_channel_datastore_add(chan, datastore);