[PATCH master 1/3] commands: readline: fix memory leak on wrong usage

Sascha Hauer sha at pengutronix.de
Mon Mar 22 09:18:54 GMT 2021


On Mon, Mar 22, 2021 at 07:55:25AM +0100, Ahmad Fatoum wrote:
> Later error-handling frees buf, but the first early exit doesn't.
> Move buf beyond it to fix the memory leak.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---

Applied, thanks

Sascha

>  commands/readline.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/commands/readline.c b/commands/readline.c
> index 403ac8563a36..7933a58c08b4 100644
> --- a/commands/readline.c
> +++ b/commands/readline.c
> @@ -10,11 +10,13 @@
>  
>  static int do_readline(int argc, char *argv[])
>  {
> -	char *buf = xzalloc(CONFIG_CBSIZE);
> +	char *buf;
>  
>  	if (argc < 3)
>  		return COMMAND_ERROR_USAGE;
>  
> +	buf = xzalloc(CONFIG_CBSIZE);
> +
>  	command_slice_release();
>  
>  	if (readline(argv[1], buf, CONFIG_CBSIZE) < 0) {
> -- 
> 2.29.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list