diff --git a/test/posix-mock-test.cc b/test/posix-mock-test.cc index 521eb035..a8eb1829 100644 --- a/test/posix-mock-test.cc +++ b/test/posix-mock-test.cc @@ -34,6 +34,7 @@ #include #include #include +#include #ifdef _WIN32 # include @@ -247,11 +248,11 @@ TEST(FileTest, OpenRetry) { TEST(FileTest, CloseNoRetryInDtor) { File read_end, write_end; File::pipe(read_end, write_end); - File *f = new File(std::move(read_end)); + std::auto_ptr f(new File(std::move(read_end))); int saved_close_count = 0; EXPECT_WRITE(stderr, { close_count = 1; - delete f; + f.reset(); saved_close_count = close_count; close_count = 0; }, format_system_error(EINTR, "cannot close file") + "\n"); diff --git a/test/posix-test.cc b/test/posix-test.cc index 4a9db7e3..10f92d72 100644 --- a/test/posix-test.cc +++ b/test/posix-test.cc @@ -26,6 +26,7 @@ */ #include +#include #include "gtest-extra.h" #include "posix.h" @@ -136,14 +137,14 @@ TEST(BufferedFileTest, CloseFileInDtor) { } TEST(BufferedFileTest, CloseErrorInDtor) { - BufferedFile *f = new BufferedFile(open_buffered_file()); + std::auto_ptr f(new BufferedFile(open_buffered_file())); EXPECT_WRITE(stderr, { // The close function must be called inside EXPECT_WRITE, otherwise // the system may recycle closed file descriptor when redirecting the // output in EXPECT_STDERR and the second close will break output // redirection. FMT_POSIX(close(f->fileno())); - SUPPRESS_ASSERT(delete f); + SUPPRESS_ASSERT(f.reset()); }, format_system_error(EBADF, "cannot close file") + "\n"); }