diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/abstract_jb.c | 4 | ||||
-rw-r--r-- | main/aoc.c | 24 | ||||
-rw-r--r-- | main/app.c | 13 | ||||
-rw-r--r-- | main/cli.c | 78 |
4 files changed, 84 insertions, 35 deletions
diff --git a/main/abstract_jb.c b/main/abstract_jb.c index 1c9eb5172..6e776c0cc 100644 --- a/main/abstract_jb.c +++ b/main/abstract_jb.c @@ -445,7 +445,7 @@ static int create_jb(struct ast_channel *chan, struct ast_frame *frr) /* Create a frame log file */ if (ast_test_flag(jbconf, AST_JB_LOG)) { - RAII_VAR(struct ast_channel *, bridged, ast_channel_bridge_peer(chan), ast_channel_cleanup); + struct ast_channel *bridged = ast_channel_bridge_peer(chan); char safe_logfile[30] = "/tmp/logfile-XXXXXX"; int safe_fd; @@ -481,6 +481,8 @@ static int create_jb(struct ast_channel *chan, struct ast_frame *frr) jb_framelog("JB_PUT_FIRST {now=%ld}: Dropped frame with ts=%ld and len=%ld\n", now, frr->ts, frr->len); } + + ast_channel_cleanup(bridged); } ast_verb(3, "%s jitterbuffer created on channel %s\n", jbimpl->name, ast_channel_name(chan)); diff --git a/main/aoc.c b/main/aoc.c index 707dbb00f..725e91071 100644 --- a/main/aoc.c +++ b/main/aoc.c @@ -1664,7 +1664,7 @@ static struct ast_json *currency_to_json(const char *name, int cost, static struct ast_json *charge_to_json(const struct ast_aoc_decoded *decoded) { - RAII_VAR(struct ast_json *, obj, NULL, ast_json_unref); + struct ast_json *obj; const char *obj_type; if (decoded->charge_type != AST_AOC_CHARGE_CURRENCY && @@ -1686,7 +1686,7 @@ static struct ast_json *charge_to_json(const struct ast_aoc_decoded *decoded) "Type", aoc_charge_type_str(decoded->charge_type), "BillingID", aoc_billingid_str(decoded->billing_id), "TotalType", aoc_type_of_totaling_str(decoded->total_type), - obj_type, ast_json_ref(obj)); + obj_type, obj); } static struct ast_json *association_to_json(const struct ast_aoc_decoded *decoded) @@ -1715,8 +1715,8 @@ static struct ast_json *s_to_json(const struct ast_aoc_decoded *decoded) for (i = 0; i < decoded->aoc_s_count; ++i) { struct ast_json *rate; - RAII_VAR(struct ast_json *, type, NULL, ast_json_unref); - RAII_VAR(struct ast_json *, currency, NULL, ast_json_unref); + struct ast_json *type = NULL; + struct ast_json *currency; const char *charge_item = aoc_charged_item_str( decoded->aoc_s_entries[i].charged_item); @@ -1731,8 +1731,8 @@ static struct ast_json *s_to_json(const struct ast_aoc_decoded *decoded) switch (decoded->aoc_s_entries[i].rate_type) { case AST_AOC_RATE_TYPE_DURATION: { - RAII_VAR(struct ast_json *, time, NULL, ast_json_unref); - RAII_VAR(struct ast_json *, granularity, NULL, ast_json_unref); + struct ast_json *time; + struct ast_json *granularity = NULL; currency = currency_to_json( decoded->aoc_s_entries[i].rate.duration.currency_name, @@ -1750,11 +1750,11 @@ static struct ast_json *s_to_json(const struct ast_aoc_decoded *decoded) } type = ast_json_pack("{s:o, s:s, s:o, s:o}", - "Currency", ast_json_ref(currency), + "Currency", currency, "ChargingType", decoded->aoc_s_entries[i].rate.duration.charging_type ? "StepFunction" : "ContinuousCharging", - "Time", ast_json_ref(time), - "Granularity", granularity ? ast_json_ref(granularity) : ast_json_null()); + "Time", time, + "Granularity", granularity ?: ast_json_null()); break; } @@ -1764,7 +1764,7 @@ static struct ast_json *s_to_json(const struct ast_aoc_decoded *decoded) decoded->aoc_s_entries[i].rate.flat.amount, decoded->aoc_s_entries[i].rate.flat.multiplier); - type = ast_json_pack("{s:o}", "Currency", ast_json_ref(currency)); + type = ast_json_pack("{s:o}", "Currency", currency); break; case AST_AOC_RATE_TYPE_VOLUME: currency = currency_to_json( @@ -1775,7 +1775,7 @@ static struct ast_json *s_to_json(const struct ast_aoc_decoded *decoded) type = ast_json_pack("{s:s, s:o}", "Unit", aoc_volume_unit_str( decoded->aoc_s_entries[i].rate.volume.volume_unit), - "Currency", ast_json_ref(currency)); + "Currency", currency); break; case AST_AOC_RATE_TYPE_SPECIAL_CODE: type = ast_json_pack("{s:i}", @@ -1787,7 +1787,7 @@ static struct ast_json *s_to_json(const struct ast_aoc_decoded *decoded) rate = ast_json_pack("{s:s, s:o}", "Chargeable", charge_item, - aoc_rate_type_str(decoded->aoc_s_entries[i].rate_type), ast_json_ref(type)); + aoc_rate_type_str(decoded->aoc_s_entries[i].rate_type), type); if (ast_json_array_append(rates, rate)) { break; } diff --git a/main/app.c b/main/app.c index 8ea6f82d9..04aca2b8c 100644 --- a/main/app.c +++ b/main/app.c @@ -3149,7 +3149,7 @@ struct stasis_topic *ast_mwi_topic(const char *uniqueid) struct ast_mwi_state *ast_mwi_create(const char *mailbox, const char *context) { - RAII_VAR(struct ast_mwi_state *, mwi_state, NULL, ao2_cleanup); + struct ast_mwi_state *mwi_state; ast_assert(!ast_strlen_zero(mailbox)); @@ -3159,6 +3159,7 @@ struct ast_mwi_state *ast_mwi_create(const char *mailbox, const char *context) } if (ast_string_field_init(mwi_state, 256)) { + ao2_ref(mwi_state, -1); return NULL; } if (!ast_strlen_zero(context)) { @@ -3167,7 +3168,6 @@ struct ast_mwi_state *ast_mwi_create(const char *mailbox, const char *context) ast_string_field_set(mwi_state, uniqueid, mailbox); } - ao2_ref(mwi_state, +1); return mwi_state; } @@ -3340,8 +3340,8 @@ struct stasis_message *ast_mwi_blob_create(struct ast_mwi_state *mwi_state, struct stasis_message_type *message_type, struct ast_json *blob) { - RAII_VAR(struct ast_mwi_blob *, obj, NULL, ao2_cleanup); - RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); + struct ast_mwi_blob *obj; + struct stasis_message *msg; ast_assert(blob != NULL); @@ -3360,11 +3360,8 @@ struct stasis_message *ast_mwi_blob_create(struct ast_mwi_state *mwi_state, /* This is not a normal MWI event. Only used by the MinivmNotify app. */ msg = stasis_message_create(message_type, obj); - if (!msg) { - return NULL; - } + ao2_ref(obj, -1); - ao2_ref(msg, +1); return msg; } diff --git a/main/cli.c b/main/cli.c index f3411860c..8e0cc3bd3 100644 --- a/main/cli.c +++ b/main/cli.c @@ -2463,18 +2463,17 @@ static char *parse_args(const char *s, int *argc, const char *argv[], int max, i /*! \brief Return the number of unique matches for the generator */ int ast_cli_generatornummatches(const char *text, const char *word) { - int matches = 0, i = 0; - char *buf = NULL, *oldbuf = NULL; - - while ((buf = ast_cli_generator(text, word, i++))) { - if (!oldbuf || strcmp(buf,oldbuf)) - matches++; - if (oldbuf) - ast_free(oldbuf); - oldbuf = buf; - } - if (oldbuf) - ast_free(oldbuf); + int matches; + struct ast_vector_string *vec = ast_cli_completion_vector(text, word); + + if (!vec) { + return 0; + } + + matches = AST_VECTOR_SIZE(vec) - 1; + AST_VECTOR_CALLBACK_VOID(vec, ast_free); + AST_VECTOR_PTR_FREE(vec); + return matches; } @@ -2501,6 +2500,44 @@ char **ast_cli_completion_matches(const char *text, const char *word) return match_list; } +AST_THREADSTORAGE_RAW(completion_storage); + +/*! + * \internal + * \brief Add a value to the vector. + * + * \param vec Vector to add \a value to. Must be from threadstorage. + * \param value The value to add. + * + * \retval 0 Success + * \retval -1 Failure + */ +static int cli_completion_vector_add(struct ast_vector_string *vec, char *value) +{ + if (!value) { + return 0; + } + + if (!vec || AST_VECTOR_ADD_SORTED(vec, value, strcasecmp)) { + if (vec) { + ast_threadstorage_set_ptr(&completion_storage, NULL); + + AST_VECTOR_CALLBACK_VOID(vec, ast_free); + AST_VECTOR_FREE(vec); + } + ast_free(value); + + return -1; + } + + return 0; +} + +int ast_cli_completion_add(char *value) +{ + return cli_completion_vector_add(ast_threadstorage_get_ptr(&completion_storage), value); +} + struct ast_vector_string *ast_cli_completion_vector(const char *text, const char *word) { char *retstr, *prevstr; @@ -2508,13 +2545,23 @@ struct ast_vector_string *ast_cli_completion_vector(const char *text, const char size_t which = 0; struct ast_vector_string *vec = ast_calloc(1, sizeof(*vec)); + /* Recursion into this function is a coding error. */ + ast_assert(!ast_threadstorage_get_ptr(&completion_storage)); + if (!vec) { return NULL; } + if (ast_threadstorage_set_ptr(&completion_storage, vec)) { + ast_log(LOG_ERROR, "Failed to initialize threadstorage for completion.\n"); + ast_free(vec); + + return NULL; + } + while ((retstr = ast_cli_generator(text, word, which)) != NULL) { - if (AST_VECTOR_ADD_SORTED(vec, retstr, strcasecmp)) { - ast_free(retstr); + if (cli_completion_vector_add(vec, retstr)) { + ast_threadstorage_set_ptr(&completion_storage, NULL); goto vector_cleanup; } @@ -2522,6 +2569,8 @@ struct ast_vector_string *ast_cli_completion_vector(const char *text, const char ++which; } + ast_threadstorage_set_ptr(&completion_storage, NULL); + if (!AST_VECTOR_SIZE(vec)) { AST_VECTOR_PTR_FREE(vec); @@ -2560,6 +2609,7 @@ struct ast_vector_string *ast_cli_completion_vector(const char *text, const char retstr = ast_strndup(AST_VECTOR_GET(vec, 0), max_equal); if (!retstr || AST_VECTOR_INSERT_AT(vec, 0, retstr)) { ast_free(retstr); + goto vector_cleanup; } |