summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Gix <brian.gix@intel.com>2020-05-15 18:22:02 -0700
committerAbhay Agarwal <ay.agarwal@samsung.com>2020-05-22 09:53:44 +0530
commit5ffa23ee564f86d647446cf45e4c8d2150e97d40 (patch)
tree9d6fe498f583d28925b7c0f9538613c5eda7faa0
parent06e0aee843d757f674b5548b2ba72dda5542dc8f (diff)
downloadbluez-5ffa23ee564f86d647446cf45e4c8d2150e97d40.tar.gz
bluez-5ffa23ee564f86d647446cf45e4c8d2150e97d40.tar.bz2
bluez-5ffa23ee564f86d647446cf45e4c8d2150e97d40.zip
mesh: Fix valgrind memory leaks
These memory leaks are ones that will compound over time with node creation and deletion. Change-Id: I67f757af13ea4d90676756ee6e1b786cefddef46 Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
-rw-r--r--mesh/mesh-config-json.c16
-rw-r--r--mesh/mesh.c5
-rw-r--r--mesh/node.c1
3 files changed, 13 insertions, 9 deletions
diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index d64e078c..a00638d4 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -448,8 +448,6 @@ static bool read_app_keys(json_object *jobj, struct mesh_config_node *node)
if (!len)
return true;
- node->appkeys = l_queue_new();
-
for (i = 0; i < len; ++i) {
json_object *jtemp, *jvalue;
char *str;
@@ -506,8 +504,6 @@ static bool read_net_keys(json_object *jobj, struct mesh_config_node *node)
if (!len)
return false;
- node->netkeys = l_queue_new();
-
for (i = 0; i < len; ++i) {
json_object *jtemp, *jvalue;
char *str;
@@ -1134,8 +1130,6 @@ static bool parse_elements(json_object *jelems, struct mesh_config_node *node)
/* Allow "empty" nodes */
return true;
- node->elements = l_queue_new();
-
for (i = 0; i < num_ele; ++i) {
json_object *jelement;
json_object *jmodels;
@@ -1155,6 +1149,7 @@ static bool parse_elements(json_object *jelems, struct mesh_config_node *node)
ele = l_new(struct mesh_config_element, 1);
ele->index = index;
ele->models = l_queue_new();
+ l_queue_push_tail(node->elements, ele);
if (!json_object_object_get_ex(jelement, "location", &jvalue))
goto fail;
@@ -1168,8 +1163,6 @@ static bool parse_elements(json_object *jelems, struct mesh_config_node *node)
!parse_models(jmodels, ele))
goto fail;
}
-
- l_queue_push_tail(node->elements, ele);
}
return true;
@@ -2134,6 +2127,11 @@ static bool load_node(const char *fname, const uint8_t uuid[16],
goto done;
memset(&node, 0, sizeof(node));
+
+ node.elements = l_queue_new();
+ node.netkeys = l_queue_new();
+ node.appkeys = l_queue_new();
+
result = read_node(jnode, &node);
if (result) {
@@ -2149,6 +2147,7 @@ static bool load_node(const char *fname, const uint8_t uuid[16],
result = cb(&node, uuid, cfg, user_data);
if (!result) {
+ l_free(cfg->idles);
l_free(cfg->node_dir_path);
l_free(cfg);
}
@@ -2158,6 +2157,7 @@ static bool load_node(const char *fname, const uint8_t uuid[16],
l_free(node.net_transmit);
l_queue_destroy(node.netkeys, l_free);
l_queue_destroy(node.appkeys, l_free);
+ l_queue_destroy(node.elements, free_element);
if (!result)
json_object_put(jnode);
diff --git a/mesh/mesh.c b/mesh/mesh.c
index 51115b4f..6cacacac 100644
--- a/mesh/mesh.c
+++ b/mesh/mesh.c
@@ -208,7 +208,7 @@ static void parse_settings(const char *mesh_conf_fname)
settings = l_settings_new();
if (!l_settings_load_from_file(settings, mesh_conf_fname))
- return;
+ goto done;
str = l_settings_get_string(settings, "General", "Beacon");
if (str) {
@@ -241,6 +241,9 @@ static void parse_settings(const char *mesh_conf_fname)
if (l_settings_get_uint(settings, "General", "ProvTimeout", &value))
mesh.prov_timeout = value;
+
+done:
+ l_settings_free(settings);
}
bool mesh_init(const char *config_dir, const char *mesh_conf_fname,
diff --git a/mesh/node.c b/mesh/node.c
index eec163d9..7084871c 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -335,6 +335,7 @@ static void free_node_resources(void *data)
free_node_dbus_resources(node);
+ mesh_config_release(node->cfg);
mesh_net_free(node->net);
l_free(node->storage_dir);
l_free(node);