Fix: src.ctf.lttng-live: possible memory leak on error path
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 15 May 2019 19:43:44 +0000 (15:43 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 29 May 2019 03:10:56 +0000 (23:10 -0400)
Free `struct lttng_live_component` if the graph is found to be already
canceled and return the appropriate _END status.

Reported-by: scan-build - Potential leak of memory.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I975e458ed4ce5dc3e50c9bf330a2f6953e5be535
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1308
Tested-by: jenkins
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
plugins/ctf/lttng-live/lttng-live.c

index ef33c776c6a91e32664bdb4a4f3710cfdd68c839..d7c1b458336b0bf33d14f917e434668c006ff0c7 100644 (file)
@@ -1471,6 +1471,9 @@ end:
 static
 void lttng_live_component_destroy_data(struct lttng_live_component *lttng_live)
 {
+       if (!lttng_live) {
+               return;
+       }
        if (lttng_live->params.url) {
                g_string_free(lttng_live->params.url, TRUE);
        }
@@ -1576,25 +1579,30 @@ bt_self_component_status lttng_live_component_init(
        lttng_live = lttng_live_component_create(params);
        if (!lttng_live) {
                ret = BT_SELF_COMPONENT_STATUS_NOMEM;
-               goto end;
+               goto error;
        }
        lttng_live->self_comp = self_comp;
 
        if (lttng_live_graph_is_canceled(lttng_live)) {
-               goto end;
+               ret = BT_SELF_COMPONENT_STATUS_END;
+               goto error;
        }
 
        ret = bt_self_component_source_add_output_port(
                                lttng_live->self_comp, "out",
                                NULL, NULL);
        if (ret != BT_SELF_COMPONENT_STATUS_OK) {
-               goto end;
+               goto error;
        }
 
        bt_self_component_set_data(
                        bt_self_component_source_as_self_component(self_comp),
                        lttng_live);
+       goto end;
 
+error:
+       lttng_live_component_destroy_data(lttng_live);
+       lttng_live = NULL;
 end:
        return ret;
 }
This page took 0.027792 seconds and 4 git commands to generate.