naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
594167
From 9e37cb1855c8fc1667f7e404376070952c015788 Mon Sep 17 00:00:00 2001
594167
From: Yu Watanabe <watanabe.yu+github@gmail.com>
594167
Date: Tue, 22 Feb 2022 21:38:15 +0900
594167
Subject: [PATCH] test: fix file descriptor leak in test-oomd-util
594167
594167
Fixes an issue reported in #22576.
594167
594167
(cherry picked from commit 282696ce52471f5e3c963b9d98dbc89fba3a1fba)
594167
Related: #2087652
594167
---
594167
 src/oom/test-oomd-util.c | 5 ++++-
594167
 1 file changed, 4 insertions(+), 1 deletion(-)
594167
594167
diff --git a/src/oom/test-oomd-util.c b/src/oom/test-oomd-util.c
594167
index 265e77c0a2..0252ceecd7 100644
594167
--- a/src/oom/test-oomd-util.c
594167
+++ b/src/oom/test-oomd-util.c
594167
@@ -5,6 +5,7 @@
594167
 #include "alloc-util.h"
594167
 #include "cgroup-setup.h"
594167
 #include "cgroup-util.h"
594167
+#include "fd-util.h"
594167
 #include "fileio.h"
594167
 #include "fs-util.h"
594167
 #include "oomd-util.h"
594167
@@ -13,6 +14,7 @@
594167
 #include "string-util.h"
594167
 #include "strv.h"
594167
 #include "tests.h"
594167
+#include "tmpfile-util.h"
594167
 
594167
 static int fork_and_sleep(unsigned sleep_min) {
594167
         usec_t n, timeout, ts;
594167
@@ -244,12 +246,13 @@ static void test_oomd_update_cgroup_contexts_between_hashmaps(void) {
594167
 
594167
 static void test_oomd_system_context_acquire(void) {
594167
         _cleanup_(unlink_tempfilep) char path[] = "/oomdgetsysctxtestXXXXXX";
594167
+        _cleanup_close_ int fd = -1;
594167
         OomdSystemContext ctx;
594167
 
594167
         if (geteuid() != 0)
594167
                 return (void) log_tests_skipped("not root");
594167
 
594167
-        assert_se(mkstemp(path));
594167
+        assert_se((fd = mkostemp_safe(path)) >= 0);
594167
 
594167
         assert_se(oomd_system_context_acquire("/verylikelynonexistentpath", &ctx) == -ENOENT);
594167