]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
tests: Avoid leaking file descriptors
authorAaron Merey <amerey@redhat.com>
Fri, 31 Jan 2025 01:21:03 +0000 (20:21 -0500)
committerAaron Merey <amerey@redhat.com>
Fri, 7 Feb 2025 22:13:51 +0000 (17:13 -0500)
Add calls to close for all test programs that leak file descriptors
in order to prevent test failures when run under valgrind
--track-fds=yes.

Signed-off-by: Aaron Merey <amerey@redhat.com>
16 files changed:
tests/all-dwarf-ranges.c
tests/alldts.c
tests/dwarf-getmacros.c
tests/dwarf-ranges.c
tests/dwarfcfi.c
tests/dwfl-core-noncontig.c
tests/early-offscn.c
tests/ecp.c
tests/newfile.c
tests/rerequest_tag.c
tests/test-elf_cntl_gelf_getshdr.c
tests/test-flag-nobits.c
tests/update1.c
tests/update2.c
tests/update3.c
tests/update4.c

index 4331a05b10e3ec83695e8d11d17c5228eb82f3c4..5924c0ffb29273d97031c09f7956f13b026ef2b6 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <inttypes.h>
+#include <unistd.h>
 
 static void
 ranges_die (Dwarf_Die *die)
@@ -85,6 +86,7 @@ main (int argc, char *argv[])
       walk_tree (&die);
     }
   dwarf_end (dbg);
+  close (fd);
 
   return 0;
 }
index d0fe4f24139b4e2e91225a0da6cd795e8d0c6cad..cd12c14d9646ae947dcce27497b5c12f398a8b7c 100644 (file)
@@ -268,5 +268,6 @@ main (void)
       return 1;
     }
 
+  close (fd);
   return 0;
 }
index 8381d42c05e863341ef812fc580ed371082f7548..a9f90ee4b897963958cdee80ed10ec724561cf1e 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <inttypes.h>
+#include <unistd.h>
 
 static void include (Dwarf *dbg, Dwarf_Off macoff, ptrdiff_t token);
 
@@ -174,6 +175,6 @@ main (int argc, char *argv[])
     }
 
   dwarf_end (dbg);
-
+  close (fd);
   return 0;
 }
index 4bcf96ce78d4970fd1da2f0c97ceb5209e385e91..e111a608c13cf26ac02ad7e04a0e0e3b928ff0f7 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <inttypes.h>
+#include <unistd.h>
 
 int
 main (int argc, char *argv[])
@@ -52,6 +53,6 @@ main (int argc, char *argv[])
               start, end, base);
 
   dwarf_end (dbg);
-
+  close (fd);
   return 0;
 }
index 29849e71641ab1cea36ee91f85b621a38db0ffeb..5f25228dd66df64444f1e091c0a6036a8c36b8df 100644 (file)
@@ -170,6 +170,7 @@ main (int argc, char *argv[])
 
   dwarf_end (dwarf);
   elf_end (elf);
+  close (fd);
 
   return result;
 }
index 04558e28e169ff32b59274e58da612558de0838d..f4170206532aa6fa6b350fb0bc37efed5db984ca 100644 (file)
@@ -21,6 +21,7 @@
 #include <assert.h>
 #include ELFUTILS_HEADER(dwfl)
 #include ELFUTILS_HEADER(elf)
+#include <unistd.h>
 
 static const Dwfl_Callbacks cb =
 {
@@ -77,6 +78,7 @@ main (int argc, char **argv)
 
   dwfl_end (dwfl);
   elf_end (elf);
+  close (fd);
 
   return 0;
 }
index af29da5a842758516315c3a93e1854a9b1683901..9ebba29c0201bb8097eebc8719b8d22205abedf1 100644 (file)
@@ -48,5 +48,6 @@ main (int argc, char *argv[])
     error (3, 0, "gelf_offscn: %s", elf_errmsg (-1));
 
   elf_end (elf);
+  close (fd);
   return 0;
 }
index 44a7bda25061cf71b4a01ae1497be246ceb019ba..eb16eb4a2833d303c57dd2b6004fc845a4e6da6b 100644 (file)
@@ -94,6 +94,7 @@ main (int argc, char *argv[])
   close (outfd);
 
   elf_end (inelf);
+  close (infd);
 
   return 0;
 }
index 5eabdcb70a4385c6b579dbe49e015d2a08d2687b..be3bd42aca3eca15e844decaa8382e921f6c1da3 100644 (file)
@@ -166,5 +166,6 @@ main (int argc, char *argv[] __attribute__ ((unused)))
       (void) elf_end (elf);
     }
 
+  close (fd);
   return result;
 }
index b4d46271a05c6c895cf89549913a9b3f4e47120f..058b8c49bdd9e4e2f3e1fdc35d0bc0d12732d963 100644 (file)
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
+#include <unistd.h>
 
 int
 main (int argc, char **argv)
@@ -43,5 +44,6 @@ main (int argc, char **argv)
   assert (dwarf_tag (die) == 0);
 
   dwarf_end (dw);
+  close (i);
   return 0;
 }
index 7371110c75e27f154c19a2c33279ac8a529f8b69..a73593340e239c628c898659ce299dbaae50478b 100644 (file)
@@ -103,5 +103,9 @@ main (int argc, char *argv[])
     }
 
   elf_end (elf);
+
+  if (!close_fd)
+    close (fd);
+
   exit (0);
 }
index 15d44ea8cd73592e6b22426dfa038e152295b0d8..c6658d9fbb6e26feeed925e5e5723d79884117d9 100644 (file)
@@ -21,6 +21,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <gelf.h>
+#include <unistd.h>
 
 int
 main (int argc, char **argv)
@@ -38,5 +39,6 @@ main (int argc, char **argv)
     elf_flagdata (elf_getdata (scn, NULL), ELF_C_SET, ELF_F_DIRTY);
 
   elf_end (stripped);
+  close (fd);
   return 0;
 }
index b7be4e5f8d96ac25f3021e34a0967b700aed15ef..4d436126c7b5b5a9f31900beefacca07415120e7 100644 (file)
@@ -123,6 +123,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
     }
 
   unlink (fname);
+  close (fd);
 
   return 0;
 }
index 714556337c5fa948a8cc1cbfd41baacca3e4ef91..f5d7230fff144449badd43440d79de5ecda12c20 100644 (file)
@@ -146,6 +146,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
     }
 
   unlink (fname);
+  close (fd);
 
   return 0;
 }
index 62f67f74f4d9736c32c98d4dbcf53007460f2b5f..9f2adab5866c290676f3e62156fea6972bfedce2 100644 (file)
@@ -201,6 +201,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
     }
 
   unlink (fname);
+  close (fd);
 
   return 0;
 }
index a703b592b55b36baa6669ed17174c0813107e028..30d2b9f153dd166d60e67b76e2f6bc9003794c2d 100644 (file)
@@ -353,6 +353,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
     }
 
   unlink (fname);
+  close (fd);
 
   return 0;
 }