public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] ubifs-utils: common: fix memory leak in devtable.c
@ 2025-04-24 18:19 ant.v.moryakov
  2025-04-25  3:22 ` Zhihao Cheng
  0 siblings, 1 reply; 4+ messages in thread
From: ant.v.moryakov @ 2025-04-24 18:19 UTC (permalink / raw)
  To: linux-mtd; +Cc: AntonMoryakov

From: AntonMoryakov <ant.v.moryakov@gmail.com>

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.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.co

---
 ubifs-utils/common/devtable.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ubifs-utils/common/devtable.c b/ubifs-utils/common/devtable.c
index 7347f09..2e581ff 100644
--- a/ubifs-utils/common/devtable.c
+++ b/ubifs-utils/common/devtable.c
@@ -392,6 +392,7 @@ int parse_devtable(const char *tbl_file)
 
 out_close:
 	fclose(f);
+	free(line);
 	free_devtable_info();
 	return -1;
 }
-- 
2.34.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ubifs-utils: common: fix memory leak in devtable.c
  2025-04-24 18:19 ant.v.moryakov
@ 2025-04-25  3:22 ` Zhihao Cheng
  0 siblings, 0 replies; 4+ messages in thread
From: Zhihao Cheng @ 2025-04-25  3:22 UTC (permalink / raw)
  To: ant.v.moryakov, linux-mtd

在 2025/4/25 2:19, ant.v.moryakov@gmail.com 写道:
> From: AntonMoryakov <ant.v.moryakov@gmail.com>
> 
> 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.
> 
> Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.co
> 
> ---
>   ubifs-utils/common/devtable.c | 1 +
>   1 file changed, 1 insertion(+)


According to the realization of getline[1], feel free to add:

Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>

[1] https://github.com/bminor/glibc/blob/master/libio/iogetdelim.c#L40
> 
> diff --git a/ubifs-utils/common/devtable.c b/ubifs-utils/common/devtable.c
> index 7347f09..2e581ff 100644
> --- a/ubifs-utils/common/devtable.c
> +++ b/ubifs-utils/common/devtable.c
> @@ -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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] ubifs-utils: common: fix memory leak in devtable.c
@ 2025-05-15  8:25 Anton Moryakov
  2025-06-02  5:35 ` David Oberhollenzer
  0 siblings, 1 reply; 4+ messages in thread
From: Anton Moryakov @ 2025-05-15  8:25 UTC (permalink / raw)
  To: linux-mtd; +Cc: david.oberhollenzer, Anton Moryakov, Zhihao Cheng

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.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>

---
 ubifs-utils/common/devtable.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ubifs-utils/common/devtable.c b/ubifs-utils/common/devtable.c
index 7347f09..2e581ff 100644
--- a/ubifs-utils/common/devtable.c
+++ b/ubifs-utils/common/devtable.c
@@ -392,6 +392,7 @@ int parse_devtable(const char *tbl_file)
 
 out_close:
 	fclose(f);
+	free(line);
 	free_devtable_info();
 	return -1;
 }
--
2.34.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ubifs-utils: common: fix memory leak in devtable.c
  2025-05-15  8:25 [PATCH] ubifs-utils: common: fix memory leak in devtable.c Anton Moryakov
@ 2025-06-02  5:35 ` David Oberhollenzer
  0 siblings, 0 replies; 4+ messages in thread
From: David Oberhollenzer @ 2025-06-02  5:35 UTC (permalink / raw)
  To: Anton Moryakov, linux-mtd; +Cc: Zhihao Cheng

Applied to mtd-utils.git master.

Thanks,

David

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-02  5:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-15  8:25 [PATCH] ubifs-utils: common: fix memory leak in devtable.c Anton Moryakov
2025-06-02  5:35 ` David Oberhollenzer
  -- strict thread matches above, loose matches on Subject: below --
2025-04-24 18:19 ant.v.moryakov
2025-04-25  3:22 ` Zhihao Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox