ubifs-utils: common: fix memory leak in devtable.c
PATCH 1/1 ubifs-utils: common: fix memory leak in devtable.c
From: AntonMoryakov <[email protected]>
Report of the static analyzer:
Dynamic memory, referenced by 'line', is allocated at devtable.c:356 by calling function 'getline' and lost at devtable.c:388. (line: while (getline(&line, &len, f) != -1) {)
Correct explained:
Now line is freed in any exit scenario via out_close which eliminates this error.
Triggers found by static analyzer Svace.
--- ubifs-utils/common/devtable.c | 1 + 1 file changed, 1 insertion(+)
ubifs-utils/common/devtable.c +1 -0
@@ -392,6 +392,7 @@ int parse_devtable(const char *tbl_file) out_close:fclose (f); +free (line);free_devtable_info ();return -1 ; }
Signature · 6 lines
2.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 10 lines · 在 2025/4/25 2:19, [email protected] 写道:
From: AntonMoryakov <[email protected]>
Report of the static analyzer:
Dynamic memory, referenced by 'line', is allocated at devtable.c:356 by calling function 'getline' and lost at devtable.c:388. (line: while (getline(&line, &len, f)!= -1) {)Correct explained:
Now line is freed in any exit scenario viaout_closewhich eliminates this error.
Quoted 7 lines
Triggers found by static analyzer Svace.
Signed-off-by Anton Moryakov <[email protected]--- ubifs-utils/common/devtable.c | 1 + 1 file changed, 1 insertion(+)
According to the realization of getline[1], feel free to add:
[1] https://github.com/bminor/glibc/blob/master/libio/iogetdelim.c#L40
Quoted 7 lines
ubifs-utils/common/devtable.c +0
-0
ubifs-utils/common/devtable.c int parse_devtable(const char *tbl_file) · line 398
Quoted 7 lines
ubifs-utils/common/devtable.c +1
-0@@ -392,6 +392,7 @@ int parse_devtable(const char *tbl_file) out_close:fclose (f); +free (line);free_devtable_info ();return -1 ; }
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/