Use unique_ptr<DIR> to safely release resources.
Test: builds, boots Bug: 66995913 Change-Id: Ib580501fc979b63295b180250581dc7527de76b2
This commit is contained in:
parent
8c26c46059
commit
5540b4406c
1 changed files with 4 additions and 6 deletions
10
Loop.cpp
10
Loop.cpp
|
@ -110,17 +110,16 @@ int Loop::destroyByDevice(const char *loopDevice) {
|
|||
int Loop::destroyAll() {
|
||||
ATRACE_NAME("Loop::destroyAll");
|
||||
|
||||
DIR* dir;
|
||||
struct dirent* de;
|
||||
|
||||
std::string root = "/dev/block/";
|
||||
if (!(dir = opendir(root.c_str()))) {
|
||||
auto dirp = std::unique_ptr<DIR, int (*)(DIR*)>(opendir(root.c_str()), closedir);
|
||||
if (!dirp) {
|
||||
PLOG(ERROR) << "Failed to opendir";
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Poke through all devices looking for loops
|
||||
while ((de = readdir(dir))) {
|
||||
struct dirent* de;
|
||||
while ((de = readdir(dirp.get()))) {
|
||||
auto test = std::string(de->d_name);
|
||||
if (!android::base::StartsWith(test, "loop")) continue;
|
||||
|
||||
|
@ -151,7 +150,6 @@ int Loop::destroyAll() {
|
|||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue