mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Vishnu Sanal T <t.v.s10123@gmail.com>
Cc: linux-kernel@vger.kernel.org, lasse.collin@tukaani.org
Subject: Re: [PATCH] fix: possible memory leak in unxz()
Date: Mon, 7 Oct 2024 18:50:45 -0700	[thread overview]
Message-ID: <20241007185045.00d57782b2f446acc7a78215@linux-foundation.org> (raw)
In-Reply-To: <20241006072542.66442-2-t.v.s10123@gmail.com>

On Sun,  6 Oct 2024 12:55:43 +0530 Vishnu Sanal T <t.v.s10123@gmail.com> wrote:

> Fixes possible memory leak in the function unxz() in
> lib/decompress_unxz.c forgets to free the pointer 'in', when
> the statement if (fill == NULL && flush == NULL) is true.
> 
> ...
>
> --- a/lib/decompress_unxz.c
> +++ b/lib/decompress_unxz.c
> @@ -343,13 +343,13 @@ STATIC int INIT unxz(unsigned char *in, long in_size,
>  			}
>  		} while (ret == XZ_OK);
>  
> -		if (must_free_in)
> -			free(in);
> -
>  		if (flush != NULL)
>  			free(b.out);
>  	}
>  
> +	if (must_free_in)
> +		free(in);
> +
>  	if (in_used != NULL)
>  		*in_used += b.in_pos;
>  

Looks correct.

must_free_in needn't exist - `in' is always non-NULL here.  And
free(NULL) is OK anwyay.


  parent reply	other threads:[~2024-10-08  1:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-06  7:25 Vishnu Sanal T
2024-10-06 18:17 ` Lasse Collin
2024-10-08  1:50 ` Andrew Morton [this message]
2024-10-08 14:40   ` Lasse Collin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241007185045.00d57782b2f446acc7a78215@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=lasse.collin@tukaani.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=t.v.s10123@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®