libf2fs: fix memory leak caused by get_rootdev()
PATCH 1/1 libf2fs: fix memory leak caused by get_rootdev()
memory which malloc for uevent don't free at get_rootdev(), it would cause memory leak, so free it before return.
Signed-off-by Junyong Sun <[email protected]>
--- lib/libf2fs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
lib/libf2fs.c +8 -3
@@ -637,20 +637,25 @@ char *get_rootdev() ptr =strstr (uevent,"DEVNAME" );if (!ptr) -return NULL ; + goto out_free; ret =sscanf (ptr,"DEVNAME=%s\n" , buf);if (strlen (buf) ==0 ) -return NULL ; + goto out_free; ret =strlen (buf) +5 ; rootdev =malloc (ret +1 );if (!rootdev) -return NULL ; + goto out_free; rootdev[ret] ='\0' ;snprintf (rootdev, ret +1 ,"/dev/%s" , buf); +free (uevent);return rootdev; + +out_free: +free (uevent); +return NULL ;#endif }
Signature · 8 lines
2.7.4 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel