]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
core: ofnode: Fix mem leak in error path
authorMario Six <mario.six@gdsys.cc>
Thu, 4 Oct 2018 07:22:24 +0000 (09:22 +0200)
committerSimon Glass <sjg@chromium.org>
Wed, 14 Nov 2018 17:16:27 +0000 (09:16 -0800)
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")
Signed-off-by: Mario Six <mario.six@gdsys.cc>
drivers/core/ofnode.c

index b7b7ad3a625da9cbff62bed3644067eabc72ac1f..d9b5280b2d4f163fea8b7cd34e17e7d47db36586 100644 (file)
@@ -831,8 +831,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;