From 557fe57debf46663cf8c9c9642ed396b9fc57a50 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Thu, 6 Aug 2020 19:05:23 -0700 Subject: [PATCH] Close the file descriptor returned by mkstemp --- src/fish_tests.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index c095dcb12..f02b0b92f 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -5045,10 +5045,13 @@ static void test_wcstring_tok() { static void test_wwrite_to_fd() { say(L"Testing wwrite_to_fd"); char t[] = "/tmp/fish_test_wwrite.XXXXXX"; - if (mkstemp(t) < 0) { + autoclose_fd_t tmpfd{mkstemp(t)}; + if (!tmpfd.valid()) { err(L"Unable to create temporary file"); return; } + tmpfd.close(); + size_t sizes[] = {0, 1, 2, 3, 5, 13, 23, 64, 128, 255, 4096, 4096 * 2}; for (size_t size : sizes) { autoclose_fd_t fd{open(t, O_RDWR | O_TRUNC | O_CREAT, 0666)};