]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: close a leftover file descriptor in `test-fileio` 8378/head
authorEvegeny Vereshchagin <evvers@ya.ru>
Mon, 5 Mar 2018 22:05:46 +0000 (22:05 +0000)
committerEvegeny Vereshchagin <evvers@ya.ru>
Mon, 5 Mar 2018 22:17:23 +0000 (22:17 +0000)
This should make it a bit easier to search for real file descriptor leaks.

```
$ valgrind --leak-check=full --track-fds=yes ./build/test-fileio
...
==29457==
==29457== FILE DESCRIPTORS: 4 open at exit.
==29457== Open file descriptor 3: /tmp/test-systemd_writing_tmpfile.lyV5Rc
==29457==    at 0x4B9AD9E: open (open.c:43)
==29457==    by 0x4B19B24: __gen_tempname (tempname.c:261)
==29457==    by 0x4BA5CC3: mkostemp64 (mkostemp64.c:32)
==29457==    by 0x48F739B: mkostemp_safe (fileio.c:1206)
==29457==    by 0x10D968: test_writing_tmpfile (test-fileio.c:620)
==29457==    by 0x10E930: main (test-fileio.c:767)
==29457==
```

src/test/test-fileio.c

index 3b4ee4b92a4cd1c1d633e324520f60e588186da9..c6128c9091702a18f91351ffddc1159ee6096d47 100644 (file)
@@ -610,7 +610,8 @@ static void test_writing_tmpfile(void) {
         char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX";
         _cleanup_free_ char *contents = NULL;
         size_t size;
-        int fd, r;
+        int r;
+        _cleanup_close_ int fd = -1;
         struct iovec iov[3];
 
         iov[0] = IOVEC_MAKE_STRING("abc\n");