Re: [PATCH v2 38/87] trace-cmd library: Fix possible memory leak in read_ftrace_files()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 29 Jul 2021 08:09:10 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@xxxxxxxxx> wrote:

> Some error paths in read_ftrace_files() may lead to a memory leak.
> Improved the error handling of this internal function to avoid it.

This looks more like a normal fix. Can it be moved to the front of the
queue? As it can be applied outside this patch set.

-- Steve

> 
> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@xxxxxxxxx>
> ---
>  lib/trace-cmd/trace-input.c | 19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
> index 0ced15a8..b36df98b 100644
> --- a/lib/trace-cmd/trace-input.c
> +++ b/lib/trace-cmd/trace-input.c
> @@ -720,25 +720,28 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex)
>  		}
>  	}
>  
> -	if (read4(handle, &count) < 0)
> -		return -1;
> +	ret = read4(handle, &count);
> +	if (ret < 0)
> +		goto out;
>  
>  	for (i = 0; i < count; i++) {
> -		if (read8(handle, &size) < 0)
> -			return -1;
> +		ret = read8(handle, &size);
> +		if (ret < 0)
> +			goto out;
>  		ret = read_ftrace_file(handle, size, print_all, ereg);
>  		if (ret < 0)
> -			return -1;
> +			goto out;
>  	}
>  
> +	handle->file_state = TRACECMD_FILE_FTRACE_EVENTS;
> +	ret = 0;
> +out:
>  	if (sreg) {
>  		regfree(sreg);
>  		regfree(ereg);
>  	}
>  
> -	handle->file_state = TRACECMD_FILE_FTRACE_EVENTS;
> -
> -	return 0;
> +	return ret;
>  }
>  
>  static int read_event_files(struct tracecmd_input *handle, const char *regex)




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux