teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0119-test-fix-file-descriptor-leak-in-test-psi-util.patch

594167
From 12274971840068b3effb7a933d62f1b5fe8009e1 Mon Sep 17 00:00:00 2001
594167
From: Yu Watanabe <watanabe.yu+github@gmail.com>
594167
Date: Tue, 22 Feb 2022 21:46:41 +0900
594167
Subject: [PATCH] test: fix file descriptor leak in test-psi-util
594167
594167
Fixes an issue reported in #22576.
594167
594167
(cherry picked from commit be99883e131ef422f8278ec1d099520996a78bb0)
594167
Related: #2087652
594167
---
594167
 src/test/test-psi-util.c | 5 ++++-
594167
 1 file changed, 4 insertions(+), 1 deletion(-)
594167
594167
diff --git a/src/test/test-psi-util.c b/src/test/test-psi-util.c
594167
index ed465b807e..111671c5a9 100644
594167
--- a/src/test/test-psi-util.c
594167
+++ b/src/test/test-psi-util.c
594167
@@ -1,20 +1,23 @@
594167
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
594167
 
594167
 #include "alloc-util.h"
594167
+#include "fd-util.h"
594167
 #include "fileio.h"
594167
 #include "fs-util.h"
594167
 #include "parse-util.h"
594167
 #include "psi-util.h"
594167
 #include "tests.h"
594167
+#include "tmpfile-util.h"
594167
 
594167
 TEST(read_mem_pressure) {
594167
         _cleanup_(unlink_tempfilep) char path[] = "/tmp/pressurereadtestXXXXXX";
594167
+        _cleanup_close_ int fd = -1;
594167
         ResourcePressure rp;
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(read_resource_pressure("/verylikelynonexistentpath", PRESSURE_TYPE_SOME, &rp) < 0);
594167
         assert_se(read_resource_pressure(path, PRESSURE_TYPE_SOME, &rp) < 0);