mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] libfile: don't leak file descriptors in compare_file
Date: Fri, 14 Apr 2023 17:20:32 +0200	[thread overview]
Message-ID: <20230414152032.3783908-1-a.fatoum@pengutronix.de> (raw)

Depending on the state of environment, running

  while saveenv; do true; done

Can quickly lead to:

  saving environment
  could not open /dev/mmc2.barebox-environment: error 24
  saveenv: error 24

Because the leaked file descriptors gobble up the 128 we have
preallocated. Fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/libfile.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/libfile.c b/lib/libfile.c
index b967232d198e..ebd1de3d8e4d 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -542,8 +542,10 @@ int compare_file(const char *f1, const char *f2)
 	if (ret)
 		goto err_out2;
 
-	if (s1.st_size != s2.st_size)
-		return 1;
+	if (s1.st_size != s2.st_size) {
+		ret = 1;
+		goto err_out2;
+	}
 
 	buf1 = xmalloc(RW_BUF_SIZE);
 	buf2 = xmalloc(RW_BUF_SIZE);
-- 
2.39.2




             reply	other threads:[~2023-04-14 15:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-14 15:20 Ahmad Fatoum [this message]
2023-04-17  6:57 ` Sascha Hauer

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=20230414152032.3783908-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox