]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
VECTOR: Passing parameters with side effects to macros is dangerous.
authorRichard Mudgett <rmudgett@digium.com>
Thu, 21 Jun 2018 21:39:45 +0000 (16:39 -0500)
committerRichard Mudgett <rmudgett@digium.com>
Thu, 21 Jun 2018 21:57:47 +0000 (16:57 -0500)
* Fix several instances where we were bumping a ref in the parameter and
then unrefing the object if it failed.  The way the AST_VECTOR_APPEND()
and AST_VECTOR_REPLACE() macros are implemented means if it fails the new
value was never evaluated.

Change-Id: I2847872a455b11ea7e5b7ce697c0a455a1d0ac9a

res/res_pjsip/pjsip_options.c
res/res_pjsip_history.c
res/stasis/messaging.c

index 2229664cc434de96f9887cd3be1bb8109d558d34..891de899cf31f3d932f4aebe3fffbd4dbf0e5f60 100644 (file)
@@ -1530,10 +1530,11 @@ static int sip_options_endpoint_compositor_add_task(void *obj)
        ast_debug(3, "Adding endpoint compositor '%s' to AOR '%s'\n",
                task_data->endpoint_state_compositor->name, task_data->aor_options->name);
 
+       ao2_ref(task_data->endpoint_state_compositor, +1);
        if (AST_VECTOR_APPEND(&task_data->aor_options->compositors,
-               ao2_bump(task_data->endpoint_state_compositor))) {
+               task_data->endpoint_state_compositor)) {
                /* Failed to add so no need to update the endpoint status.  Nothing changed. */
-               ao2_cleanup(task_data->endpoint_state_compositor);
+               ao2_ref(task_data->endpoint_state_compositor, -1);
                return 0;
        }
 
index 8f44d390e75c0cf914a6e19c75d783a425006d10..e6e9ac200bf2b7e902b6fa4d5895bd9fdee69b7c 100644 (file)
@@ -1135,7 +1135,8 @@ static struct vector_history_t *filter_history(struct ast_cli_args *a)
                } else if (!res) {
                        continue;
                } else {
-                       if (AST_VECTOR_APPEND(output, ao2_bump(entry))) {
+                       ao2_bump(entry);
+                       if (AST_VECTOR_APPEND(output, entry)) {
                                ao2_cleanup(entry);
                        }
                }
index 979b687abd67fbf424f2910286506f003b777dfe..4a86d5875578bf5f754f5d9422c8db5f5dd3e4a4 100644 (file)
@@ -459,8 +459,9 @@ static struct message_subscription *get_or_create_subscription(struct ast_endpoi
                ao2_link(endpoint_subscriptions, sub);
        } else {
                ast_rwlock_wrlock(&tech_subscriptions_lock);
-               if (AST_VECTOR_APPEND(&tech_subscriptions, ao2_bump(sub))) {
-                       /* Release the ao2_bump that was for the vector and allocation references. */
+               ao2_ref(sub, +1);
+               if (AST_VECTOR_APPEND(&tech_subscriptions, sub)) {
+                       /* Release the refs that were for the vector and the allocation. */
                        ao2_ref(sub, -2);
                        sub = NULL;
                }