diff mbox series

[BlueZ] mesh: Fix double-free

Message ID 20200520153551.832644-1-brian.gix@intel.com (mailing list archive)
State Superseded
Headers show
Series [BlueZ] mesh: Fix double-free | expand

Commit Message

Brian Gix May 20, 2020, 3:35 p.m. UTC
Fixing a prior memory leak created a double-free error when destroying
the NVM sorage of a node. We have two situations where we want to
discard a nodes dytnamic memory:

1. When the node is being deleted at runtime.  This causes release of
   both dynamic memory and NVM storage.

2. During shutdown, we release dynamic memory only.

This patch ensures that after node deletion releases dynamic memory,
the pointers to it are cleared, avoiding a second free attempt.
---
 mesh/node.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/mesh/node.c b/mesh/node.c
index 2b4b3a563..03f4d342b 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -352,8 +352,10 @@  void node_remove(struct mesh_node *node)
 
 	l_queue_remove(nodes, node);
 
-	if (node->cfg)
+	if (node->cfg) {
 		mesh_config_destroy(node->cfg);
+		node->cfg = NULL;
+	}
 
 	free_node_resources(node);
 }