Skip to contentSkip to conversation

core: ofnode: Fix mem leak in error path

PATCH New Mario Six 2 participants 2 messages Oct 4, 2018 – Oct 15, 2018

lore
Share & tools
lore

Mario Six

author
#0 lore raw

PATCH 1/1 core: ofnode: Fix mem leak in error path

A newly created property is currently not freed if a name could not be allocated. This patch fixes the resulting memory leak in the error patch.

Reported-by Coverity (CID: 184085)
Fixes e369e58df79c ("core: Add functions to set properties in live-tree")
---
 drivers/core/ofnode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/core/ofnode.c +3 -1
index 1e354803b0..5182eb7149 100644
@@ -825,8 +825,10 @@ int ofnode_write_prop(ofnode node, const char *propname, int len,
 		return -ENOMEM;
 
 	new->name = strdup(propname);
-	if (!new->name)
+	if (!new->name) {
+		free(new);
 		return -ENOMEM;
+	}
 
 	new->value = (void *)value;
 	new->length = len;

--
2.16.4

#1 lore raw

PATCH 1/1 core: ofnode: Fix mem leak in error path

A newly created property is currently not freed if a name could not be allocated. This patch fixes the resulting memory leak in the error patch.

Reported-by Coverity (CID: 184085)
Fixes e369e58df79c ("core: Add functions to set properties in live-tree")
---
 drivers/core/ofnode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!