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:
@@ -3378,7 +3378,7 @@ TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest) {
|
||||
ssize_t file_size =
|
||||
file_system.FileSize(usage_info_not_empty_app_id_file_name);
|
||||
EXPECT_LT(4, file_size);
|
||||
File* file =
|
||||
std::unique_ptr<File> file =
|
||||
file_system.Open(usage_info_not_empty_app_id_file_name,
|
||||
FileSystem::kReadOnly);
|
||||
EXPECT_TRUE(NULL != file);
|
||||
@@ -3386,7 +3386,6 @@ TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest) {
|
||||
file_data.resize(file_size);
|
||||
ssize_t bytes = file->Read(&file_data[0], file_data.size());
|
||||
EXPECT_EQ(file_size, bytes);
|
||||
file->Close();
|
||||
|
||||
// Corrupt the hash of the usage info file with non-empty app id and write
|
||||
// it back out
|
||||
@@ -3396,7 +3395,6 @@ TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest) {
|
||||
EXPECT_TRUE(NULL != file);
|
||||
bytes = file->Write(file_data.data(), file_data.size());
|
||||
EXPECT_EQ(file_size, bytes);
|
||||
file->Close();
|
||||
|
||||
EXPECT_EQ(
|
||||
NO_ERROR,
|
||||
@@ -3425,7 +3423,6 @@ TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest) {
|
||||
file_data.resize(file_size);
|
||||
bytes = file->Read(&file_data[0], file_data.size());
|
||||
EXPECT_EQ(file_size, bytes);
|
||||
file->Close();
|
||||
|
||||
// Corrupt the hash of the usage info file with empty app id and write it
|
||||
// back out
|
||||
@@ -3435,7 +3432,6 @@ TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest) {
|
||||
EXPECT_TRUE(NULL != file);
|
||||
bytes = file->Write(file_data.data(), file_data.size());
|
||||
EXPECT_EQ(file_size, bytes);
|
||||
file->Close();
|
||||
|
||||
EXPECT_EQ(
|
||||
NO_ERROR,
|
||||
@@ -3528,7 +3524,7 @@ TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest2) {
|
||||
ssize_t file_size =
|
||||
file_system.FileSize(usage_info_not_empty_app_id_file_name);
|
||||
EXPECT_LT(4, file_size);
|
||||
File* file =
|
||||
std::unique_ptr<File> file =
|
||||
file_system.Open(usage_info_not_empty_app_id_file_name,
|
||||
FileSystem::kReadOnly);
|
||||
EXPECT_TRUE(NULL != file);
|
||||
@@ -3536,7 +3532,6 @@ TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest2) {
|
||||
file_data.resize(file_size);
|
||||
ssize_t bytes = file->Read(&file_data[0], file_data.size());
|
||||
EXPECT_EQ(file_size, bytes);
|
||||
file->Close();
|
||||
|
||||
video_widevine_client::sdk::HashedFile hash_file;
|
||||
|
||||
@@ -3554,7 +3549,6 @@ TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest2) {
|
||||
EXPECT_TRUE(NULL != file);
|
||||
bytes = file->Write(file_data.data(), file_data.size());
|
||||
EXPECT_EQ(file_size, bytes);
|
||||
file->Close();
|
||||
|
||||
EXPECT_EQ(
|
||||
NO_ERROR,
|
||||
@@ -3583,7 +3577,6 @@ TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest2) {
|
||||
file_data.resize(file_size);
|
||||
bytes = file->Read(&file_data[0], file_data.size());
|
||||
EXPECT_EQ(file_size, bytes);
|
||||
file->Close();
|
||||
|
||||
EXPECT_TRUE(hash_file.ParseFromString(file_data));
|
||||
pos = file_data.find(hash_file.hash());
|
||||
@@ -3599,7 +3592,6 @@ TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest2) {
|
||||
EXPECT_TRUE(NULL != file);
|
||||
bytes = file->Write(file_data.data(), file_data.size());
|
||||
EXPECT_EQ(file_size, bytes);
|
||||
file->Close();
|
||||
|
||||
EXPECT_EQ(
|
||||
NO_ERROR,
|
||||
@@ -3826,14 +3818,13 @@ TEST_F(WvCdmRequestLicenseTest, UsageRecoveryTest) {
|
||||
// Read in usage info file
|
||||
ssize_t file_size = file_system.FileSize(usage_info_file_name);
|
||||
EXPECT_LT(4, file_size);
|
||||
File* file =
|
||||
std::unique_ptr<File> file =
|
||||
file_system.Open(usage_info_file_name, FileSystem::kReadOnly);
|
||||
EXPECT_TRUE(NULL != file);
|
||||
std::string file_data;
|
||||
file_data.resize(file_size);
|
||||
ssize_t bytes = file->Read(&file_data[0], file_data.size());
|
||||
EXPECT_EQ(file_size, bytes);
|
||||
file->Close();
|
||||
|
||||
// Corrupt the hash of the usage info file and write it back out
|
||||
memset(&file_data[0]+bytes-4, 0, 4);
|
||||
@@ -3842,7 +3833,6 @@ TEST_F(WvCdmRequestLicenseTest, UsageRecoveryTest) {
|
||||
EXPECT_TRUE(NULL != file);
|
||||
bytes = file->Write(file_data.data(), file_data.size());
|
||||
EXPECT_EQ(file_size, bytes);
|
||||
file->Close();
|
||||
|
||||
// Fetch a second usage license, this should fail as the usage table is
|
||||
// corrupt
|
||||
|
||||
Reference in New Issue
Block a user