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
This commit is contained in:
Josh Gao 2018-11-05 13:47:28 -08:00
parent 298fa3264f
commit e3c32e0d2f

View file

@ -818,7 +818,8 @@ static status_t delete_dir_contents(DIR* dir) {
result = -errno;
continue;
}
std::unique_ptr<DIR, decltype(&closedir)> subdirp(fdopendir(subfd), closedir);
std::unique_ptr<DIR, decltype(&closedir)> subdirp(
android::base::Fdopendir(std::move(subfd)), closedir);
if (!subdirp) {
PLOG(ERROR) << "Couldn't fdopendir " << name;
result = -errno;