Merge "res_pjsip_exten_state: Check for vector append failure."
authorJenkins2 <jenkins2@gerrit.asterisk.org>
Wed, 8 Nov 2017 02:06:26 +0000 (20:06 -0600)
committerGerrit Code Review <gerrit2@gerrit.digium.api>
Wed, 8 Nov 2017 02:06:27 +0000 (20:06 -0600)
25 files changed:
apps/app_mixmonitor.c
bridges/bridge_softmix.c
include/asterisk/utils.h
main/cli.c
main/db.c
main/format_cap.c
main/json.c
main/message.c
main/pbx.c
main/rtp_engine.c
main/stasis.c
main/stasis_channels.c
main/tcptls.c
main/utils.c
res/ari/resource_bridges.c
res/ari/resource_events.c
res/res_pjproject.c
res/res_pjsip/config_transport.c
res/res_pjsip/location.c
res/res_pjsip/pjsip_configuration.c
res/res_pjsip_config_wizard.c
res/res_stasis_playback.c
res/res_xmpp.c
res/stasis/app.c
tests/test_sorcery_memory_cache_thrash.c

index 2922e0c..bb47cfc 100644 (file)
@@ -813,6 +813,8 @@ static int setup_mixmonitor_ds(struct mixmonitor *mixmonitor, struct ast_channel
 
        if (ast_asprintf(datastore_id, "%p", mixmonitor_ds) == -1) {
                ast_log(LOG_ERROR, "Failed to allocate memory for MixMonitor ID.\n");
+               ast_free(mixmonitor_ds);
+               return -1;
        }
 
        ast_mutex_init(&mixmonitor_ds->lock);
index 9197df6..f490967 100644 (file)
@@ -502,7 +502,6 @@ static int append_source_streams(struct ast_stream_topology *dest,
 
                if (ast_asprintf(&stream_clone_name, "%s_%s_%s", SOFTBRIDGE_VIDEO_DEST_PREFIX,
                        channel_name, ast_stream_get_name(stream)) < 0) {
-                       ast_free(stream_clone_name);
                        return -1;
                }
 
index 423d73b..0a12b1d 100644 (file)
@@ -622,7 +622,13 @@ int __ast_vasprintf(char **ret, const char *fmt, va_list ap, const char *file, i
 
        DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);
 
-       if ((res = vasprintf(ret, fmt, ap)) == -1) {
+       res = vasprintf(ret, fmt, ap);
+       if (res < 0) {
+               /*
+                * *ret is undefined so set to NULL to ensure it is
+                * initialized to something useful.
+                */
+               *ret = NULL;
                MALLOC_FAILURE_MSG;
        }
 
index 0896181..5c16e8b 100644 (file)
@@ -1362,31 +1362,6 @@ static char *handle_commandnummatches(struct ast_cli_entry *e, int cmd, struct a
        return CLI_SUCCESS;
 }
 
-static char *handle_commandcomplete(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-       char *buf;
-       switch (cmd) {
-       case CLI_INIT:
-               e->command = "_command complete";
-               e->usage =
-                       "Usage: _command complete \"<line>\" text state\n"
-                       "       This function is used internally to help with command completion and should.\n"
-                       "       never be called by the user directly.\n";
-               return NULL;
-       case CLI_GENERATE:
-               return NULL;
-       }
-       if (a->argc != 5)
-               return CLI_SHOWUSAGE;
-       buf = __ast_cli_generator(a->argv[2], a->argv[3], atoi(a->argv[4]), 0);
-       if (buf) {
-               ast_cli(a->fd, "%s", buf);
-               ast_free(buf);
-       } else
-               ast_cli(a->fd, "NULL\n");
-       return CLI_SUCCESS;
-}
-
 struct channel_set_debug_args {
        int fd;
        int is_off;
@@ -1817,8 +1792,6 @@ static char *handle_cli_wait_fullybooted(struct ast_cli_entry *e, int cmd, struc
 static char *handle_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 
 static struct ast_cli_entry cli_cli[] = {
-       /* Deprecated, but preferred command is now consolidated (and already has a deprecated command for it). */
-       AST_CLI_DEFINE(handle_commandcomplete, "Command complete"),
        AST_CLI_DEFINE(handle_commandnummatches, "Returns number of command matches"),
        AST_CLI_DEFINE(handle_commandmatchesarray, "Returns command matches array"),
 
index 9432435..fa125d7 100644 (file)
--- a/main/db.c
+++ b/main/db.c
@@ -191,9 +191,11 @@ static int convert_bdb_to_sqlite3(void)
        char *cmd;
        int res;
 
-       ast_asprintf(&cmd, "%s/astdb2sqlite3 '%s'\n", ast_config_AST_SBIN_DIR, ast_config_AST_DB);
-       res = ast_safe_system(cmd);
-       ast_free(cmd);
+       res = ast_asprintf(&cmd, "%s/astdb2sqlite3 '%s'\n", ast_config_AST_SBIN_DIR, ast_config_AST_DB);
+       if (0 <= res) {
+               res = ast_safe_system(cmd);
+               ast_free(cmd);
+       }
 
        return res;
 }
index b0897c0..d71ccdb 100644 (file)
@@ -160,13 +160,16 @@ static inline int format_cap_framed_init(struct format_cap_framed *framed, struc
        }
        list = AST_VECTOR_GET_ADDR(&cap->formats, ast_format_get_codec_id(format));
 
+       /* This takes the allocation reference */
+       if (AST_VECTOR_APPEND(&cap->preference_order, framed)) {
+               ao2_ref(framed, -1);
+               return -1;
+       }
+
        /* Order doesn't matter for formats, so insert at the head for performance reasons */
        ao2_ref(framed, +1);
        AST_LIST_INSERT_HEAD(list, framed, entry);
 
-       /* This takes the allocation reference */
-       AST_VECTOR_APPEND(&cap->preference_order, framed);
-
        cap->framing = MIN(cap->framing, framing ? framing : ast_format_get_default_ms(format));
 
        return 0;
index 9004978..56df7f4 100644 (file)
@@ -460,7 +460,7 @@ struct ast_json *ast_json_vstringf(const char *format, va_list args)
 
        if (format) {
                int err = ast_vasprintf(&str, format, args);
-               if (err > 0) {
+               if (err >= 0) {
                        ret = json_string(str);
                        ast_free(str);
                }
index fcdf705..ac7965e 100644 (file)
@@ -1362,7 +1362,12 @@ int ast_msg_tech_register(const struct ast_msg_tech *tech)
                return -1;
        }
 
-       AST_VECTOR_APPEND(&msg_techs, tech);
+       if (AST_VECTOR_APPEND(&msg_techs, tech)) {
+               ast_log(LOG_ERROR, "Failed to register message technology for '%s'\n",
+                       tech->name);
+               ast_rwlock_unlock(&msg_techs_lock);
+               return -1;
+       }
        ast_verb(3, "Message technology '%s' registered.\n", tech->name);
 
        ast_rwlock_unlock(&msg_techs_lock);
@@ -1417,7 +1422,12 @@ int ast_msg_handler_register(const struct ast_msg_handler *handler)
                return -1;
        }
 
-       AST_VECTOR_APPEND(&msg_handlers, handler);
+       if (AST_VECTOR_APPEND(&msg_handlers, handler)) {
+               ast_log(LOG_ERROR, "Failed to register message handler for '%s'\n",
+                       handler->name);
+               ast_rwlock_unlock(&msg_handlers_lock);
+               return -1;
+       }
        ast_verb(2, "Message handler '%s' registered.\n", handler->name);
 
        ast_rwlock_unlock(&msg_handlers_lock);
index 2366b72..b5602b5 100644 (file)
@@ -6692,7 +6692,11 @@ int ast_context_add_include2(struct ast_context *con, const char *value,
        }
 
        /* ... include new context into context list, unlock, return */
-       AST_VECTOR_APPEND(&con->includes, new_include);
+       if (AST_VECTOR_APPEND(&con->includes, new_include)) {
+               include_free(new_include);
+               ast_unlock_context(con);
+               return -1;
+       }
        ast_verb(3, "Including context '%s' in context '%s'\n",
                ast_get_include_name(new_include), ast_get_context_name(con));
 
@@ -6754,7 +6758,11 @@ int ast_context_add_switch2(struct ast_context *con, const char *value,
        }
 
        /* ... sw new context into context list, unlock, return */
-       AST_VECTOR_APPEND(&con->alts, new_sw);
+       if (AST_VECTOR_APPEND(&con->alts, new_sw)) {
+               sw_free(new_sw);
+               ast_unlock_context(con);
+               return -1;
+       }
 
        ast_verb(3, "Including switch '%s/%s' in context '%s'\n",
                ast_get_switch_name(new_sw), ast_get_switch_data(new_sw), ast_get_context_name(con));
@@ -6842,7 +6850,11 @@ int ast_context_add_ignorepat2(struct ast_context *con, const char *value, const
                        return -1;
                }
        }
-       AST_VECTOR_APPEND(&con->ignorepats, ignorepat);
+       if (AST_VECTOR_APPEND(&con->ignorepats, ignorepat)) {
+               ignorepat_free(ignorepat);
+               ast_unlock_context(con);
+               return -1;
+       }
        ast_unlock_context(con);
 
        return 0;
index 0aed8e9..2431ffc 100644 (file)
@@ -802,7 +802,10 @@ static void rtp_codecs_payload_replace_rx(struct ast_rtp_codecs *codecs, int pay
                ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_rx, payload),
                        "cleaning up rx mapping vector element about to be replaced");
        }
-       AST_VECTOR_REPLACE(&codecs->payload_mapping_rx, payload, new_type);
+       if (AST_VECTOR_REPLACE(&codecs->payload_mapping_rx, payload, new_type)) {
+               ao2_ref(new_type, -1);
+               return;
+       }
 
        payload_mapping_rx_clear_primary(codecs, new_type);
 }
@@ -924,7 +927,10 @@ static void rtp_codecs_payloads_copy_tx(struct ast_rtp_codecs *src, struct ast_r
                        ao2_t_cleanup(AST_VECTOR_GET(&dest->payload_mapping_tx, idx),
                                "cleaning up tx mapping vector element about to be replaced");
                }
-               AST_VECTOR_REPLACE(&dest->payload_mapping_tx, idx, type);
+               if (AST_VECTOR_REPLACE(&dest->payload_mapping_tx, idx, type)) {
+                       ao2_ref(type, -1);
+                       continue;
+               }
 
                if (instance && instance->engine && instance->engine->payload_set) {
                        ao2_lock(instance);
@@ -1038,9 +1044,10 @@ void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct as
                        ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, payload),
                                "cleaning up replaced tx payload type");
                }
-               AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, new_type);
 
-               if (instance && instance->engine && instance->engine->payload_set) {
+               if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, new_type)) {
+                       ao2_ref(new_type, -1);
+               } else if (instance && instance->engine && instance->engine->payload_set) {
                        ao2_lock(instance);
                        instance->engine->payload_set(instance, payload, new_type->asterisk_format, new_type->format, new_type->rtp_code);
                        ao2_unlock(instance);
@@ -1116,9 +1123,10 @@ int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs,
                                ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, pt),
                                        "cleaning up replaced tx payload type");
                        }
-                       AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, pt, new_type);
 
-                       if (instance && instance->engine && instance->engine->payload_set) {
+                       if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, pt, new_type)) {
+                               ao2_ref(new_type, -1);
+                       } else if (instance && instance->engine && instance->engine->payload_set) {
                                ao2_lock(instance);
                                instance->engine->payload_set(instance, pt, new_type->asterisk_format, new_type->format, new_type->rtp_code);
                                ao2_unlock(instance);
@@ -1215,7 +1223,9 @@ int ast_rtp_codecs_payload_replace_format(struct ast_rtp_codecs *codecs, int pay
                if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
                        ao2_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, payload));
                }
-               AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, type);
+               if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, type)) {
+                       ao2_ref(type, -1);
+               }
        } else {
                ao2_ref(type, -1);
        }
index a82e938..186d88f 100644 (file)
@@ -908,7 +908,7 @@ struct stasis_forward *stasis_forward_all(struct stasis_topic *from_topic,
 {
        int res;
        size_t idx;
-       RAII_VAR(struct stasis_forward *, forward, NULL, ao2_cleanup);
+       struct stasis_forward *forward;
 
        if (!from_topic || !to_topic) {
                return NULL;
@@ -921,7 +921,7 @@ struct stasis_forward *stasis_forward_all(struct stasis_topic *from_topic,
 
        /* Forwards to ourselves are implicit. */
        if (to_topic == from_topic) {
-               return ao2_bump(forward);
+               return forward;
        }
 
        forward->from_topic = ao2_bump(from_topic);
@@ -932,6 +932,7 @@ struct stasis_forward *stasis_forward_all(struct stasis_topic *from_topic,
        if (res != 0) {
                ao2_unlock(from_topic);
                ao2_unlock(to_topic);
+               ao2_ref(forward, -1);
                return NULL;
        }
 
@@ -941,7 +942,7 @@ struct stasis_forward *stasis_forward_all(struct stasis_topic *from_topic,
        ao2_unlock(from_topic);
        ao2_unlock(to_topic);
 
-       return ao2_bump(forward);
+       return forward;
 }
 
 static void subscription_change_dtor(void *obj)
@@ -1239,10 +1240,9 @@ struct ast_multi_object_blob *ast_multi_object_blob_create(struct ast_json *blob
 void ast_multi_object_blob_add(struct ast_multi_object_blob *multi,
        enum stasis_user_multi_object_snapshot_type type, void *object)
 {
-       if (!multi || !object) {
-               return;
+       if (!multi || !object || AST_VECTOR_APPEND(&multi->snapshots[type], object)) {
+               ao2_cleanup(object);
        }
-       AST_VECTOR_APPEND(&multi->snapshots[type],object);
 }
 
 /*! \brief Publish single channel user event (for app_userevent compatibility) */
@@ -1342,7 +1342,7 @@ static struct ast_str *multi_object_blob_to_ami(void *obj)
 
        for (type = 0; type < STASIS_UMOS_MAX; ++type) {
                for (i = 0; i < AST_VECTOR_SIZE(&multi->snapshots[type]); ++i) {
-                       char *name = "";
+                       char *name = NULL;
                        void *snapshot = AST_VECTOR_GET(&multi->snapshots[type], i);
                        ami_snapshot = NULL;
 
@@ -1352,11 +1352,11 @@ static struct ast_str *multi_object_blob_to_ami(void *obj)
 
                        switch (type) {
                        case STASIS_UMOS_CHANNEL:
-                               ami_snapshot = ast_manager_build_channel_state_string_prefix(snapshot, name);
+                               ami_snapshot = ast_manager_build_channel_state_string_prefix(snapshot, name ?: "");
                                break;
 
                        case STASIS_UMOS_BRIDGE:
-                               ami_snapshot = ast_manager_build_bridge_state_string_prefix(snapshot, name);
+                               ami_snapshot = ast_manager_build_bridge_state_string_prefix(snapshot, name ?: "");
                                break;
 
                        case STASIS_UMOS_ENDPOINT:
@@ -1367,6 +1367,7 @@ static struct ast_str *multi_object_blob_to_ami(void *obj)
                                ast_str_append(&ami_str, 0, "%s", ast_str_buffer(ami_snapshot));
                                ast_free(ami_snapshot);
                        }
+                       ast_free(name);
                }
        }
 
index dd71b86..b81dbe5 100644 (file)
@@ -891,7 +891,7 @@ struct ast_json *ast_channel_snapshot_to_json(
        const struct ast_channel_snapshot *snapshot,
        const struct stasis_message_sanitizer *sanitize)
 {
-       RAII_VAR(struct ast_json *, json_chan, NULL, ast_json_unref);
+       struct ast_json *json_chan;
 
        if (snapshot == NULL
                || (sanitize && sanitize->channel_snapshot
@@ -924,7 +924,7 @@ struct ast_json *ast_channel_snapshot_to_json(
                ast_json_object_set(json_chan, "channelvars", ast_json_channel_vars(snapshot->ari_vars));
        }
 
-       return ast_json_ref(json_chan);
+       return json_chan;
 }
 
 int ast_channel_snapshot_cep_equal(
index 4a95f72..a6d0538 100644 (file)
@@ -316,7 +316,10 @@ static void __ssl_setup_certs(struct ast_tls_config *cfg, const size_t cert_file
 static int __ssl_setup(struct ast_tls_config *cfg, int client)
 {
 #ifndef DO_SSL
-       cfg->enabled = 0;
+       if (cfg->enabled) {
+               ast_log(LOG_NOTICE, "Configured without OpenSSL Development Headers");
+               cfg->enabled = 0;
+       }
        return 0;
 #else
        int disable_ssl = 0;
index a73bf9d..c553207 100644 (file)
@@ -2340,7 +2340,13 @@ int __ast_asprintf(const char *file, int lineno, const char *func, char **ret, c
        va_list ap;
 
        va_start(ap, fmt);
-       if ((res = vasprintf(ret, fmt, ap)) == -1) {
+       res = vasprintf(ret, fmt, ap);
+       if (res < 0) {
+               /*
+                * *ret is undefined so set to NULL to ensure it is
+                * initialized to something useful.
+                */
+               *ret = NULL;
                MALLOC_FAILURE_MSG;
        }
        va_end(ap);
index aab78ce..cd289aa 100644 (file)
@@ -392,7 +392,6 @@ static int ari_bridges_play_helper(const char **args_media,
 
        if (ast_asprintf(playback_url, "/playbacks/%s",
                        stasis_app_playback_get_id(playback)) == -1) {
-               playback_url = NULL;
                ast_ari_response_alloc_failed(response);
                return -1;
        }
index 4be5d02..992c562 100644 (file)
@@ -108,7 +108,9 @@ static void stasis_app_message_handler(
                        msg_application);
        } else if (!session->ws_session) {
                /* If the websocket is NULL, the message goes to the queue */
-               AST_VECTOR_APPEND(&session->message_queue, message);
+               if (!AST_VECTOR_APPEND(&session->message_queue, message)) {
+                       ast_json_ref(message);
+               }
                ast_log(LOG_WARNING,
                                "Queued '%s' message for Stasis app '%s'; websocket is not ready\n",
                                msg_type,
index 46c82aa..86b2502 100644 (file)
@@ -227,11 +227,16 @@ static void log_forwarder(int level, const char *data, int len)
 
 static void capture_buildopts_cb(int level, const char *data, int len)
 {
+       char *dup;
+
        if (strstr(data, "Teluu") || strstr(data, "Dumping")) {
                return;
        }
 
-       AST_VECTOR_ADD_SORTED(&buildopts, ast_strdup(ast_skip_blanks(data)), strcmp);
+       dup = ast_strdup(ast_skip_blanks(data));
+       if (AST_VECTOR_ADD_SORTED(&buildopts, dup, strcmp)) {
+               ast_free(dup);
+       }
 }
 
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
index 0c804b8..2f29456 100644 (file)
@@ -683,6 +683,11 @@ static int transport_tls_file_handler(const struct aco_option *opt, struct ast_v
                return -1;
        }
 
+       if (ast_strlen_zero(var->value)) {
+               /* Ignore empty options */
+               return 0;
+       }
+
        if (!ast_file_is_readable(var->value)) {
                ast_log(LOG_ERROR, "Transport: %s: %s %s is either missing or not readable\n",
                        ast_sorcery_object_get_id(obj), var->name, var->value);
index 9945c7c..0d7b3da 100644 (file)
@@ -1219,6 +1219,11 @@ static int contact_apply_handler(const struct ast_sorcery *sorcery, void *object
        struct ast_sip_contact_status *status;
        struct ast_sip_contact *contact = object;
 
+       if (ast_strlen_zero(contact->uri)) {
+               ast_log(LOG_ERROR, "A URI on dynamic contact '%s' is empty\n",
+                       ast_sorcery_object_get_id(contact));
+               return -1;
+       }
        status = ast_res_pjsip_find_or_create_contact_status(contact);
        ao2_cleanup(status);
 
index a6afe5e..168d869 100644 (file)
@@ -508,6 +508,8 @@ int ast_sip_auth_vector_init(struct ast_sip_auth_vector *auths, const char *valu
                        goto failure;
                }
                if (AST_VECTOR_APPEND(auths, val)) {
+                       ast_free(val);
+
                        goto failure;
                }
        }
index 1526dc2..3a761a7 100644 (file)
@@ -1001,7 +1001,10 @@ static int wizard_apply_handler(const struct ast_sorcery *sorcery, struct object
                char *hosts = ast_strdupa(remote_hosts);
 
                while ((host = ast_strsep(&hosts, ',', AST_STRSEP_TRIM))) {
-                       AST_VECTOR_APPEND(&remote_hosts_vector, ast_strdup(host));
+                       host = ast_strdup(host);
+                       if (host && AST_VECTOR_APPEND(&remote_hosts_vector, host)) {
+                               ast_free(host);
+                       }
                }
        }
 
@@ -1168,15 +1171,22 @@ static void wizard_mapped_observer(const char *name, struct ast_sorcery *sorcery
        /* We're only interested in memory wizards with the pjsip_wizard tag. */
        if (wizard_args && !strcmp(wizard_args, "pjsip_wizard")) {
                otw = ast_malloc(sizeof(*otw) + strlen(object_type) + 1);
+               if (!otw) {
+                       return;
+               }
+
                otw->sorcery = sorcery;
                otw->wizard = wizard;
                otw->wizard_data = wizard_data;
                otw->last_config = NULL;
                strcpy(otw->object_type, object_type); /* Safe */
                AST_VECTOR_RW_WRLOCK(&object_type_wizards);
-               AST_VECTOR_APPEND(&object_type_wizards, otw);
+               if (AST_VECTOR_APPEND(&object_type_wizards, otw)) {
+                       ast_free(otw);
+               } else {
+                       ast_debug(1, "Wizard mapped for object_type '%s'\n", object_type);
+               }
                AST_VECTOR_RW_UNLOCK(&object_type_wizards);
-               ast_debug(1, "Wizard mapped for object_type '%s'\n", object_type);
        }
 }
 
index c6f2136..ca0446b 100644 (file)
@@ -497,7 +497,11 @@ struct stasis_app_playback *stasis_app_control_play_uri(
 
            /* safe */
                strcpy(media_uri, media[i]);
-               AST_VECTOR_APPEND(&playback->medias, media_uri);
+               if (AST_VECTOR_APPEND(&playback->medias, media_uri)) {
+                       ao2_ref(playback, -1);
+                       ast_free(media_uri);
+                       return NULL;
+               }
        }
 
        if (skipms == 0) {
index 8a06a6c..f683557 100644 (file)
@@ -3909,8 +3909,11 @@ static int fetch_access_token(struct ast_xmpp_client_config *cfg)
        struct ast_json_error error;
        RAII_VAR(struct ast_json *, jobj, NULL, ast_json_unref);
 
-       ast_asprintf(&cmd, "CURL(%s,client_id=%s&client_secret=%s&refresh_token=%s&grant_type=refresh_token)",
-                    url, cfg->oauth_clientid, cfg->oauth_secret, cfg->refresh_token);
+       if (ast_asprintf(&cmd,
+               "CURL(%s,client_id=%s&client_secret=%s&refresh_token=%s&grant_type=refresh_token)",
+               url, cfg->oauth_clientid, cfg->oauth_secret, cfg->refresh_token) < 0) {
+               return -1;
+       }
 
        ast_debug(2, "Performing OAuth 2.0 authentication for client '%s' using command: %s\n",
                cfg->name, cmd);
index b0bcf3c..0b44bf3 100644 (file)
@@ -871,9 +871,21 @@ int stasis_app_get_debug(struct stasis_app *app)
 
 int stasis_app_get_debug_by_name(const char *app_name)
 {
-       RAII_VAR(struct stasis_app *, app, stasis_app_get_by_name(app_name), ao2_cleanup);
+       int debug_enabled = 0;
 
-       return (app ? app->debug : 0) || global_debug;
+       if (global_debug) {
+               debug_enabled = 1;
+       } else {
+               struct stasis_app *app = stasis_app_get_by_name(app_name);
+
+               if (app) {
+                       if (app->debug) {
+                               debug_enabled = 1;
+                       }
+                       ao2_ref(app, -1);
+               }
+       }
+       return debug_enabled;
 }
 
 void stasis_app_set_global_debug(int debug)
index c0d25fe..dfe7a7c 100644 (file)
@@ -218,7 +218,11 @@ static struct sorcery_memory_cache_thrash *sorcery_memory_cache_thrash_create(co
                /* This purposely holds no ref as the main thrash structure does */
                thread->sorcery = thrash->sorcery;
 
-               AST_VECTOR_APPEND(&thrash->threads, thread);
+               if (AST_VECTOR_APPEND(&thrash->threads, thread)) {
+                       ast_free(thread);
+                       ao2_ref(thrash, -1);
+                       return NULL;
+               }
        }
 
        return thrash;