mesh: Fix memory leak when failing to load a node
authorInga Stotland <inga.stotland@intel.com>
Tue, 10 Nov 2020 04:24:51 +0000 (20:24 -0800)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 28 Dec 2020 06:20:04 +0000 (11:50 +0530)
This fixes a memory leak that may occur on unsuccessful element
initialization from storage.

Change-Id: I2a1b928280d58a3077f9ba1c30682a0041bfb9ab
Signed-off-by: anuj.bhumiya <anuj.bhumiya@samsung.com>
mesh/node.c

index f6c270e..dc85123 100644 (file)
@@ -342,16 +342,13 @@ static bool add_element_from_storage(struct mesh_node *node,
 
        ele->idx = db_ele->index;
        ele->location = db_ele->location;
-
-
-       if (!ele->models)
-               ele->models = l_queue_new();
+       ele->models = l_queue_new();
+       l_queue_push_tail(node->elements, ele);
 
        if (!mesh_model_add_from_storage(node, ele->idx, ele->models,
                                                        db_ele->models))
                return false;
 
-       l_queue_push_tail(node->elements, ele);
        return true;
 }