From e3c32e0d2f120deca4809a282bea914e5d5b0a15 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Mon, 5 Nov 2018 13:47:28 -0800 Subject: [PATCH] Avoid double close in delete_dir_contents. fdopendir takes ownership of the file descriptor, leading to it being closed by both unique_fd's destructor and closedir. Test: treehugger Change-Id: Ibd193e988c77c5323720531445f334c0795c68b9 --- Utils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Utils.cpp b/Utils.cpp index 8af616d..f7afde5 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -818,7 +818,8 @@ static status_t delete_dir_contents(DIR* dir) { result = -errno; continue; } - std::unique_ptr subdirp(fdopendir(subfd), closedir); + std::unique_ptr subdirp( + android::base::Fdopendir(std::move(subfd)), closedir); if (!subdirp) { PLOG(ERROR) << "Couldn't fdopendir " << name; result = -errno;