Skip to contentSkip to conversation

ubifs-utils: common: fix memory leak in devtable.c

PATCH In review [email protected] 2 participants 2 messages Apr 24, 2025 – Apr 25, 2025 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

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
index 7347f09..2e581ff 100644
@@ -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/
Reviewed-by on v1 1/1
#1 lore raw
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 via out_close which eliminates this error.

Quoted 7 lines

Triggers found by static analyzer Svace.

---
  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
index 7347f09..2e581ff 100644

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/