diff options
author | Martin Anderseck <martin.anderseck@ni.com> | 2021-08-04 09:45:39 +0200 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-08-04 07:05:20 -0500 |
commit | ae82759d004fa62c60b7ec36041f7f242e6bf22d (patch) | |
tree | 3a75142be040c609a2e09cfe4c9b96274b81aee5 | |
parent | cd0adcd43a6067ca8c9b717bc5d5d26f79738183 (diff) | |
download | uhd-ae82759d004fa62c60b7ec36041f7f242e6bf22d.tar.gz uhd-ae82759d004fa62c60b7ec36041f7f242e6bf22d.tar.bz2 uhd-ae82759d004fa62c60b7ec36041f7f242e6bf22d.zip |
test: Fix potential resource leak
Fixed issue where variable tmp_file going out of scope could have
leaked the storage it points to. Replaced the declaration of tmp_file
by using a unique pointer with custom deleter that takes care of
closing the tmpfile when it is not needed anymore.
-rw-r--r-- | host/tests/isatty_test.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/host/tests/isatty_test.cpp b/host/tests/isatty_test.cpp index 786023dc3..990366896 100644 --- a/host/tests/isatty_test.cpp +++ b/host/tests/isatty_test.cpp @@ -5,7 +5,7 @@ // #include <uhdlib/utils/isatty.hpp> -#include <stdio.h> +#include <cstdio> #include <boost/test/unit_test.hpp> #include <iostream> @@ -18,12 +18,11 @@ BOOST_AUTO_TEST_CASE(test_isatty) } else { std::cout << "stderr is not a TTY" << std::endl; } - - FILE* tmp_file = std::tmpfile(); + auto tmp_file = std::unique_ptr<std::FILE, decltype(&std::fclose)>(std::tmpfile(), &std::fclose); #ifdef UHD_PLATFORM_WIN32 - BOOST_REQUIRE(!uhd::is_a_tty(_fileno(tmp_file))); + BOOST_REQUIRE(!uhd::is_a_tty(_fileno(tmp_file.get()))); #elif _POSIX_C_SOURCE >= _200112L - BOOST_REQUIRE(!uhd::is_a_tty(fileno(tmp_file))); + BOOST_REQUIRE(!uhd::is_a_tty(fileno(tmp_file.get()))); #else // I got 99 problems but dealing with portability ain't one BOOST_REQUIRE(!uhd::is_a_tty(99)); |