summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-04-14 17:20:32 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2023-04-17 08:56:54 +0200
commit0caba41d5cc84fa8d1299a99f4dc4ea2d939026f (patch)
tree836b59b8830ed49ebd3d14480c82e8f0683fbf9d /lib
parent14b296d2a7e6088c8be9095a2d3a14ce0b4b4172 (diff)
downloadbarebox-0caba41d5cc84fa8d1299a99f4dc4ea2d939026f.tar.gz
libfile: don't leak file descriptors in compare_file
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> Link: https://lore.barebox.org/20230414152032.3783908-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/libfile.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/libfile.c b/lib/libfile.c
index b967232d19..ebd1de3d8e 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);