Merge "Convert ifstream usage into fopen() to prevent fd leaks into child processes" am: 93fb6083d4
am: f1dec58b61
Change-Id: Id7e8626129dbda0fdafcc86b087b67f71b5d3f8a
This commit is contained in:
commit
1efcfc30b1
1 changed files with 12 additions and 3 deletions
15
Process.cpp
15
Process.cpp
|
@ -46,18 +46,27 @@ namespace vold {
|
|||
|
||||
static bool checkMaps(const std::string& path, const std::string& prefix) {
|
||||
bool found = false;
|
||||
std::ifstream infile(path);
|
||||
std::string line;
|
||||
while (std::getline(infile, line)) {
|
||||
auto file = std::unique_ptr<FILE, decltype(&fclose)>{fopen(path.c_str(), "re"), fclose};
|
||||
if (!file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char* buf = nullptr;
|
||||
size_t len = 0;
|
||||
while (getline(&buf, &len, file.get()) != -1) {
|
||||
std::string line(buf);
|
||||
std::string::size_type pos = line.find('/');
|
||||
if (pos != std::string::npos) {
|
||||
line = line.substr(pos);
|
||||
if (android::base::StartsWith(line, prefix)) {
|
||||
LOG(WARNING) << "Found map " << path << " referencing " << line;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue