All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: 周恺航 <22321077@zju.edu.cn>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: Fix resource leak in iptables/xtables-restore.c
Date: Mon, 12 May 2025 12:23:28 +0200	[thread overview]
Message-ID: <aCHMICSGU2LT7SS-@orbyte.nwl.cc> (raw)
In-Reply-To: <87aa5c8.77e3.196c354f80c.Coremail.22321077@zju.edu.cn>

Hi,

On Mon, May 12, 2025 at 03:10:47PM +0800, 周恺航 wrote:
> The function xtables_restore_main opens a file stream p.in but fails to close it before returning. This leads to a resource leak as the file descriptor remains open.
> 
> 
> Signed-off-by: Kaihang Zhou <22321077@zju.edu.cn>
> 
> ---
>  iptables/xtables-restore.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> 
> diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c
> 
> index e7802b9e..f09ab7ee 100644
> --- a/iptables/xtables-restore.c
> +++ b/iptables/xtables-restore.c
> @@ -381,6 +381,7 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
>                 break;
>         default:
>                 fprintf(stderr, "Unknown family %d\n", family);
> +               fclose(p.in);
>                 return 1;
>         }

Since this is not the only error path which leaves p.in open (eight
lines below is the next one for instance), why fix this one in
particular and leave the other ones in place?

Cheers, Phil

  reply	other threads:[~2025-05-12 10:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-12  7:10 Fix resource leak in iptables/xtables-restore.c 周恺航
2025-05-12 10:23 ` Phil Sutter [this message]
2025-05-13  5:20   ` 周恺航
2025-05-13 15:57     ` Phil Sutter

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=aCHMICSGU2LT7SS-@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --cc=22321077@zju.edu.cn \
    --cc=netfilter-devel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.