Message ID | 20250424181922.17531-1-ant.v.moryakov@gmail.com |
---|---|
State | Superseded |
Delegated to: | David Oberhollenzer |
Headers | show |
Series | ubifs-utils: common: fix memory leak in devtable.c | expand |
在 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; > } >
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; }