2021-02-20 08:49:39

by Zhiqiang Liu

[permalink] [raw]
Subject: [PATCH] debugfs: fix memory leak problem in read_list()


In read_list func, if strtoull() fails in while loop,
we will return the error code directly. Then, memory of
variable lst will be leaked without setting to *list.

Signed-off-by: Zhiqiang Liu <[email protected]>
Signed-off-by: linfeilong <[email protected]>
---
debugfs/util.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/debugfs/util.c b/debugfs/util.c
index be6b550e..9e880548 100644
--- a/debugfs/util.c
+++ b/debugfs/util.c
@@ -530,12 +530,16 @@ errcode_t read_list(char *str, blk64_t **list, size_t *len)

errno = 0;
y = x = strtoull(tok, &e, 0);
- if (errno)
- return errno;
+ if (errno) {
+ retval = errno;
+ break;
+ }
if (*e == '-') {
y = strtoull(e + 1, NULL, 0);
- if (errno)
- return errno;
+ if (errno) {
+ retval = errno;
+ break;
+ }
} else if (*e != 0) {
retval = EINVAL;
break;
--
2.19.1



2021-02-25 05:54:17

by Zhiqiang Liu

[permalink] [raw]
Subject: Re: [PATCH] debugfs: fix memory leak problem in read_list()

friendly ping ...

On 2021/2/20 16:41, Zhiqiang Liu wrote:
>
> In read_list func, if strtoull() fails in while loop,
> we will return the error code directly. Then, memory of
> variable lst will be leaked without setting to *list.
>
> Signed-off-by: Zhiqiang Liu <[email protected]>
> Signed-off-by: linfeilong <[email protected]>
> ---
> debugfs/util.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/debugfs/util.c b/debugfs/util.c
> index be6b550e..9e880548 100644
> --- a/debugfs/util.c
> +++ b/debugfs/util.c
> @@ -530,12 +530,16 @@ errcode_t read_list(char *str, blk64_t **list, size_t *len)
>
> errno = 0;
> y = x = strtoull(tok, &e, 0);
> - if (errno)
> - return errno;
> + if (errno) {
> + retval = errno;
> + break;
> + }
> if (*e == '-') {
> y = strtoull(e + 1, NULL, 0);
> - if (errno)
> - return errno;
> + if (errno) {
> + retval = errno;
> + break;
> + }
> } else if (*e != 0) {
> retval = EINVAL;
> break;
>