]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_stasis: Fix multiple leaks.
authorCorey Farrell <git@cfware.com>
Mon, 6 Nov 2017 23:21:53 +0000 (18:21 -0500)
committerCorey Farrell <git@cfware.com>
Tue, 7 Nov 2017 16:24:51 +0000 (11:24 -0500)
* res/stasis/app.c JSON passed to app_send needs to be released.
* res/stasis_message.c: objects leak if vector append fails.

Change-Id: I8dd5385b9f50a5cadf2b1d16efecffd6ddb4db4a

res/stasis/app.c
res/stasis/messaging.c

index 7d88c1b6ef0c2634aea632a2922892aa7209c45f..1e885c6f82b612a98f7245e27f424f228faef308 100644 (file)
@@ -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;
 }
index d2df3ff0c9effcc99e649962ccedfc51b4b1d750..979b687abd67fbf424f2910286506f003b777dfe 100644 (file)
@@ -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 --");