Refactor file_store to use smart pointers
Bug: b/119276649 Merge of http://go/wvgerrit/68903 Test: Android + 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:
@@ -59,7 +59,7 @@ OldUsageTable::OldUsageTable(CryptoEngine *ce) {
|
||||
|
||||
// Load saved table.
|
||||
wvcdm::FileSystem* file_system = ce->file_system();
|
||||
wvcdm::File *file;
|
||||
std::unique_ptr<wvcdm::File> file;
|
||||
std::string path;
|
||||
// Note: this path is OK for a real implementation, but using security level 1
|
||||
// would be better.
|
||||
@@ -90,7 +90,6 @@ OldUsageTable::OldUsageTable(CryptoEngine *ce) {
|
||||
return;
|
||||
}
|
||||
file->Read(reinterpret_cast<char *>(&encrypted_buffer[0]), file_size);
|
||||
file->Close();
|
||||
|
||||
// Verify the signature of the usage table file.
|
||||
|
||||
@@ -141,7 +140,6 @@ OldUsageTable::OldUsageTable(CryptoEngine *ce) {
|
||||
return;
|
||||
}
|
||||
file->Read(reinterpret_cast<char *>(&generation_), sizeof(int64_t));
|
||||
file->Close();
|
||||
if (stored_table->generation == generation_ + 1) {
|
||||
if (LogCategoryEnabled(kLoggingTraceUsageTable)) {
|
||||
LOGW("OldUsageTable: File is one generation old. Acceptable rollback.");
|
||||
|
||||
Reference in New Issue
Block a user