Refactor file_store to use smart pointers
Bug: b/119276649 Merge from: http://go/wvgerrit/66367 Test: Android, CE CDM, Linux unit tests The FileSystem interface as it exists expects an Open for a file and then a Close when finished. However, the Close doesn't delete the file itself and depending on the platform, the underlying impl_ as well, leading to a memory leak. To fix this leak as well as harden against future memory issues, this change refactors the interface to shift away from raw pointers and towards smart pointers. Change-Id: I7a7132ea95cd3775796a540f510b698f4f27dd24
This commit is contained in:
@@ -1152,7 +1152,7 @@ bool DeviceFiles::StoreFileRaw(const std::string& name,
|
||||
|
||||
path += name;
|
||||
|
||||
File* file =
|
||||
auto file =
|
||||
file_system_->Open(path, FileSystem::kCreate | FileSystem::kTruncate);
|
||||
if (!file) {
|
||||
LOGW("DeviceFiles::StoreFileRaw: File open failed: %s", path.c_str());
|
||||
@@ -1160,7 +1160,6 @@ bool DeviceFiles::StoreFileRaw(const std::string& name,
|
||||
}
|
||||
|
||||
ssize_t bytes = file->Write(serialized_file.data(), serialized_file.size());
|
||||
file->Close();
|
||||
|
||||
if (bytes != static_cast<ssize_t>(serialized_file.size())) {
|
||||
LOGW(
|
||||
@@ -1208,7 +1207,7 @@ bool DeviceFiles::RetrieveHashedFile(
|
||||
return false;
|
||||
}
|
||||
|
||||
File* file = file_system_->Open(path, FileSystem::kReadOnly);
|
||||
auto file = file_system_->Open(path, FileSystem::kReadOnly);
|
||||
if (!file) {
|
||||
return false;
|
||||
}
|
||||
@@ -1216,7 +1215,6 @@ bool DeviceFiles::RetrieveHashedFile(
|
||||
std::string serialized_hash_file;
|
||||
serialized_hash_file.resize(bytes);
|
||||
bytes = file->Read(&serialized_hash_file[0], serialized_hash_file.size());
|
||||
file->Close();
|
||||
|
||||
if (bytes != static_cast<ssize_t>(serialized_hash_file.size())) {
|
||||
LOGW("DeviceFiles::RetrieveHashedFile: read failed");
|
||||
|
||||
Reference in New Issue
Block a user