summaryrefslogtreecommitdiff
path: root/src/tmpfiles
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-01-09 10:52:30 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-01-09 10:52:33 +0900
commit8a555dcbf776886cbfbafe1ee9c7482d81d11378 (patch)
tree3c8cebba4aa1e1354531d9346ee4295be9f764bd /src/tmpfiles
parent4f79f545b3c46c358666c9f5f2b384fe50aac4b4 (diff)
downloadsystemd-8a555dcbf776886cbfbafe1ee9c7482d81d11378.tar.gz
tmpfile: fix resource leak
Fixes CID#1501687.
Diffstat (limited to 'src/tmpfiles')
-rw-r--r--src/tmpfiles/offline-passwd.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/tmpfiles/offline-passwd.c b/src/tmpfiles/offline-passwd.c
index 4ffed1c102..085286e992 100644
--- a/src/tmpfiles/offline-passwd.c
+++ b/src/tmpfiles/offline-passwd.c
@@ -11,13 +11,14 @@ DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(uid_gid_hash_ops, char, string_hash_
static int open_passwd_file(const char *root, const char *fname, FILE **ret_file) {
_cleanup_free_ char *p = NULL, *bn = NULL;
_cleanup_close_ int fd = -EBADF;
+ _cleanup_fclose_ FILE *f = NULL;
int r;
fd = chase_symlinks_and_open(fname, root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC, &p);
if (fd < 0)
return fd;
- FILE *f = fdopen(fd, "r");
+ f = fdopen(fd, "r");
if (!f)
return -errno;
@@ -29,7 +30,7 @@ static int open_passwd_file(const char *root, const char *fname, FILE **ret_file
log_debug("Reading %s entries from %s...", bn, p);
- *ret_file = f;
+ *ret_file = TAKE_PTR(f);
return 0;
}