diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/db.c | 8 | ||||
-rw-r--r-- | main/json.c | 2 | ||||
-rw-r--r-- | main/rtp_engine.c | 23 | ||||
-rw-r--r-- | main/stasis.c | 7 | ||||
-rw-r--r-- | main/utils.c | 8 |
5 files changed, 32 insertions, 16 deletions
@@ -193,9 +193,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; } diff --git a/main/json.c b/main/json.c index f45d585c1..057a26212 100644 --- a/main/json.c +++ b/main/json.c @@ -462,7 +462,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); } diff --git a/main/rtp_engine.c b/main/rtp_engine.c index d82bc4980..e7032724b 100644 --- a/main/rtp_engine.c +++ b/main/rtp_engine.c @@ -728,10 +728,11 @@ void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_cod ao2_t_cleanup(AST_VECTOR_GET(&dest->payloads, i), "cleaning up vector element about to be replaced"); } ast_debug(2, "Copying payload %d (%p) from %p to %p\n", i, type, src, dest); - ao2_bump(type); - AST_VECTOR_REPLACE(&dest->payloads, i, type); - if (instance && instance->engine && instance->engine->payload_set) { + ao2_bump(type); + if (AST_VECTOR_REPLACE(&dest->payloads, i, type)) { + ao2_cleanup(type); + } else if (instance && instance->engine && instance->engine->payload_set) { ao2_lock(instance); instance->engine->payload_set(instance, i, type->asterisk_format, type->format, type->rtp_code); ao2_unlock(instance); @@ -767,9 +768,10 @@ void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct as if (payload < AST_VECTOR_SIZE(&codecs->payloads)) { ao2_t_cleanup(AST_VECTOR_GET(&codecs->payloads, payload), "cleaning up replaced payload type"); } - AST_VECTOR_REPLACE(&codecs->payloads, payload, new_type); - if (instance && instance->engine && instance->engine->payload_set) { + if (AST_VECTOR_REPLACE(&codecs->payloads, 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); @@ -837,9 +839,10 @@ int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, /* SDP parsing automatically increases the reference count */ new_type->format = ast_format_parse_sdp_fmtp(new_type->format, ""); } - AST_VECTOR_REPLACE(&codecs->payloads, pt, new_type); - if (instance && instance->engine && instance->engine->payload_set) { + if (AST_VECTOR_REPLACE(&codecs->payloads, 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); @@ -929,7 +932,11 @@ int ast_rtp_codecs_payload_replace_format(struct ast_rtp_codecs *codecs, int pay if (payload < AST_VECTOR_SIZE(&codecs->payloads)) { ao2_cleanup(AST_VECTOR_GET(&codecs->payloads, payload)); } - AST_VECTOR_REPLACE(&codecs->payloads, payload, type); + if (AST_VECTOR_REPLACE(&codecs->payloads, payload, type)) { + ao2_ref(type, -1); + ast_rwlock_unlock(&codecs->codecs_lock); + return -1; + } ast_rwlock_unlock(&codecs->codecs_lock); return 0; diff --git a/main/stasis.c b/main/stasis.c index 48e4eb5a5..2d9980517 100644 --- a/main/stasis.c +++ b/main/stasis.c @@ -1344,7 +1344,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; @@ -1354,11 +1354,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: @@ -1369,6 +1369,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); } } diff --git a/main/utils.c b/main/utils.c index 0824a373a..034203046 100644 --- a/main/utils.c +++ b/main/utils.c @@ -2389,7 +2389,13 @@ int _ast_asprintf(char **ret, const char *file, int lineno, const char *func, co 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); |