]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-unit-name: fix fd leak 26115/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 20 Jan 2023 05:54:44 +0000 (14:54 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 20 Jan 2023 05:55:46 +0000 (14:55 +0900)
Fixes an issue reported at https://github.com/systemd/systemd/issues/22576#issuecomment-1396774385.

src/test/test-unit-name.c

index c6428e844f8ecbbfc7558da6d2e57ed3f95560a7..3904126a875f4bf0ec957be1e85e8c41942a52dd 100644 (file)
@@ -242,11 +242,13 @@ TEST_RET(unit_printf, .sd_booted = true) {
                 *user, *group, *uid, *gid, *home, *shell,
                 *tmp_dir, *var_tmp_dir;
         _cleanup_(manager_freep) Manager *m = NULL;
+        _cleanup_close_ int fd = -EBADF;
         Unit *u;
         int r;
 
         _cleanup_(unlink_tempfilep) char filename[] = "/tmp/test-unit_printf.XXXXXX";
-        assert_se(mkostemp_safe(filename) >= 0);
+        fd = mkostemp_safe(filename);
+        assert_se(fd >= 0);
 
         /* Using the specifier functions is admittedly a bit circular, but we don't want to reimplement the
          * logic a second time. We're at least testing that the hookup works. */