summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/cli.c27
-rw-r--r--main/format_cap.c9
-rw-r--r--main/message.c14
-rw-r--r--main/stasis.c12
-rw-r--r--main/stasis_channels.c4
-rw-r--r--main/tcptls.c5
-rw-r--r--res/res_pjsip/config_transport.c5
-rw-r--r--res/res_pjsip/location.c5
-rw-r--r--res/res_pjsip/pjsip_configuration.c2
-rw-r--r--res/res_pjsip_config_wizard.c16
-rw-r--r--res/res_pjsip_outbound_registration.c6
-rw-r--r--res/stasis/app.c25
-rw-r--r--res/stasis/messaging.c12
-rw-r--r--tests/test_sorcery_memory_cache_thrash.c6
14 files changed, 94 insertions, 54 deletions
diff --git a/main/cli.c b/main/cli.c
index 6a5721b02..64882a3a7 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -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;
@@ -1798,8 +1773,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"),
diff --git a/main/format_cap.c b/main/format_cap.c
index fc5686652..8a00ed64d 100644
--- a/main/format_cap.c
+++ b/main/format_cap.c
@@ -177,13 +177,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;
diff --git a/main/message.c b/main/message.c
index be0035d30..caee37c81 100644
--- a/main/message.c
+++ b/main/message.c
@@ -1364,7 +1364,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);
@@ -1419,7 +1424,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);
diff --git a/main/stasis.c b/main/stasis.c
index 2d9980517..63d17dfaf 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -910,7 +910,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;
@@ -923,7 +923,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);
@@ -934,6 +934,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;
}
@@ -943,7 +944,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)
@@ -1241,10 +1242,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) */
diff --git a/main/stasis_channels.c b/main/stasis_channels.c
index d46a8ddcf..0479bd9e9 100644
--- a/main/stasis_channels.c
+++ b/main/stasis_channels.c
@@ -889,7 +889,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
@@ -918,7 +918,7 @@ struct ast_json *ast_channel_snapshot_to_json(
"creationtime", ast_json_timeval(snapshot->creationtime, NULL),
"language", snapshot->language);
- return ast_json_ref(json_chan);
+ return json_chan;
}
int ast_channel_snapshot_cep_equal(
diff --git a/main/tcptls.c b/main/tcptls.c
index 144b32f47..ef22094bf 100644
--- a/main/tcptls.c
+++ b/main/tcptls.c
@@ -874,7 +874,10 @@ void *ast_tcptls_server_root(void *data)
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;
diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c
index 0c804b82a..2f29456ab 100644
--- a/res/res_pjsip/config_transport.c
+++ b/res/res_pjsip/config_transport.c
@@ -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);
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c
index 66fc85c95..8ba409e2e 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -1226,6 +1226,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);
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index e000039d2..81234d695 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -510,6 +510,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;
}
}
diff --git a/res/res_pjsip_config_wizard.c b/res/res_pjsip_config_wizard.c
index c13ff4aca..d487c4ddd 100644
--- a/res/res_pjsip_config_wizard.c
+++ b/res/res_pjsip_config_wizard.c
@@ -1003,7 +1003,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);
+ }
}
}
@@ -1170,15 +1173,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);
}
}
diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index 731a1a939..0b177ae32 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -1386,10 +1386,10 @@ static int sip_outbound_registration_perform(void *data)
AST_VECTOR_INIT(&state->client_state->outbound_auths, AST_VECTOR_SIZE(&registration->outbound_auths));
for (i = 0; i < AST_VECTOR_SIZE(&registration->outbound_auths); ++i) {
- const char *name = ast_strdup(AST_VECTOR_GET(&registration->outbound_auths, i));
+ char *name = ast_strdup(AST_VECTOR_GET(&registration->outbound_auths, i));
- if (name) {
- AST_VECTOR_APPEND(&state->client_state->outbound_auths, name);
+ if (name && AST_VECTOR_APPEND(&state->client_state->outbound_auths, name)) {
+ ast_free(name);
}
}
state->client_state->retry_interval = registration->retry_interval;
diff --git a/res/stasis/app.c b/res/stasis/app.c
index e122f34a4..1e885c6f8 100644
--- a/res/stasis/app.c
+++ b/res/stasis/app.c
@@ -591,6 +591,7 @@ static int message_received_handler(const char *endpoint_id, struct ast_json *js
{
RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
struct ast_json *json_endpoint;
+ struct ast_json *message;
struct stasis_app *app = pvt;
char *tech;
char *resource;
@@ -616,11 +617,15 @@ static int message_received_handler(const char *endpoint_id, struct ast_json *js
return -1;
}
- app_send(app, ast_json_pack("{s: s, s: o, s: o, s: o}",
+ message = ast_json_pack("{s: s, s: o, s: o, s: o}",
"type", "TextMessageReceived",
"timestamp", ast_json_timeval(ast_tvnow(), NULL),
"endpoint", json_endpoint,
- "message", ast_json_ref(json_msg)));
+ "message", ast_json_ref(json_msg));
+ if (message) {
+ app_send(app, message);
+ ast_json_unref(message);
+ }
return 0;
}
@@ -874,9 +879,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)
diff --git a/res/stasis/messaging.c b/res/stasis/messaging.c
index d2df3ff0c..979b687ab 100644
--- a/res/stasis/messaging.c
+++ b/res/stasis/messaging.c
@@ -459,7 +459,11 @@ static struct message_subscription *get_or_create_subscription(struct ast_endpoi
ao2_link(endpoint_subscriptions, sub);
} else {
ast_rwlock_wrlock(&tech_subscriptions_lock);
- AST_VECTOR_APPEND(&tech_subscriptions, ao2_bump(sub));
+ if (AST_VECTOR_APPEND(&tech_subscriptions, ao2_bump(sub))) {
+ /* Release the ao2_bump that was for the vector and allocation references. */
+ ao2_ref(sub, -2);
+ sub = NULL;
+ }
ast_rwlock_unlock(&tech_subscriptions_lock);
}
@@ -487,7 +491,11 @@ int messaging_app_subscribe_endpoint(const char *app_name, struct ast_endpoint *
ao2_unlock(sub);
return -1;
}
- AST_VECTOR_APPEND(&sub->applications, tuple);
+ if (AST_VECTOR_APPEND(&sub->applications, tuple)) {
+ ao2_ref(tuple, -1);
+ ao2_unlock(sub);
+ return -1;
+ }
ao2_unlock(sub);
ast_debug(3, "App '%s' subscribed to messages from endpoint '%s'\n", app_name, endpoint ? ast_endpoint_get_id(endpoint) : "-- ALL --");
diff --git a/tests/test_sorcery_memory_cache_thrash.c b/tests/test_sorcery_memory_cache_thrash.c
index c0d25feb3..dfe7a7c81 100644
--- a/tests/test_sorcery_memory_cache_thrash.c
+++ b/tests/test_sorcery_memory_cache_thrash.c
@@ -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;