mesh: Fix potential memory leak
authorBrian Gix <brian.gix@intel.com>
Thu, 30 Jun 2022 21:10:13 +0000 (14:10 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:55 +0000 (14:55 +0530)
This memory leak will never happen, however since we added a new
return from function that malloc'd memory, the free should still be
done.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
mesh/mesh-config-json.c

index c683bb6..af30c17 100644 (file)
@@ -1962,8 +1962,10 @@ bool mesh_config_comp_page_add(struct mesh_config *cfg, uint8_t page,
        len = (size * 2) + 3;
        buf = l_malloc(len);
        ret = snprintf(buf, len, "%2.2x", page);
-       if (ret < 0)
+       if (ret < 0) {
+               l_free(buf);
                return false;
+       }
 
        hex2str(data, size, buf + 2, len - 2);