Skip to content

Commit

Permalink
Fix leak when parsing base64. (flutter#23547)
Browse files Browse the repository at this point in the history
The old SkBase64::decode interface required the user to delete the
result of SkBase64::getData. Use the newer SkBase64::Decode interface
which makes the memory ownership more obvious.
  • Loading branch information
bungeman committed Jan 11, 2021
1 parent 4600172 commit f5c673c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions common/graphics/persistent_cache.cc
Expand Up @@ -169,14 +169,26 @@ sk_sp<SkData> ParseBase32(const std::string& input) {
}

sk_sp<SkData> ParseBase64(const std::string& input) {
SkBase64 decoder;
auto error = decoder.decode(input.c_str(), input.length());
SkBase64::Error error;

size_t output_len;
error = SkBase64::Decode(input.c_str(), input.length(), nullptr, &output_len);
if (error != SkBase64::Error::kNoError) {
FML_LOG(ERROR) << "Base64 decode error: " << error;
FML_LOG(ERROR) << "Base64 can't decode: " << input;
return nullptr;
}

sk_sp<SkData> data = SkData::MakeUninitialized(output_len);
void* output = data->writable_data();
error = SkBase64::Decode(input.c_str(), input.length(), output, &output_len);
if (error != SkBase64::Error::kNoError) {
FML_LOG(ERROR) << "Base64 decode error: " << error;
FML_LOG(ERROR) << "Base64 can't decode: " << input;
return nullptr;
}
return SkData::MakeWithCopy(decoder.getData(), decoder.getDataSize());

return data;
}

std::vector<PersistentCache::SkSLCache> PersistentCache::LoadSkSLs() {
Expand Down

0 comments on commit f5c673c

Please sign in to comment.