Skip to content

Commit

Permalink
fix(storage, windows): getData() crash has been fixed (#12185)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Jan 23, 2024
1 parent d7998e0 commit ed8c7c5
Showing 1 changed file with 4 additions and 5 deletions.
Expand Up @@ -401,25 +401,24 @@ void FirebaseStoragePlugin::ReferenceGetData(
result) {
StorageReference cpp_reference =
GetCPPStorageReferenceFromPigeon(app, reference);
const size_t kMaxAllowedSize = 1 * 1024 * 1024;

// Use a shared pointer for automatic memory management and copyability
auto byte_buffer = std::make_shared<std::vector<uint8_t>>(kMaxAllowedSize);
auto byte_buffer = std::make_shared<std::vector<uint8_t>>(max_size);

Future<size_t> future_result =
cpp_reference.GetBytes(byte_buffer->data(), max_size);
::Sleep(1); // timing for c++ sdk grabbing a mutex

future_result.OnCompletion(
[result, byte_buffer](const Future<size_t>& data_result) {
if (data_result.error() == firebase::storage::kErrorNone) {
if (data_result.error() != firebase::storage::kErrorNone) {
result(FirebaseStoragePlugin::ParseError(data_result));
} else {
size_t vector_size = *data_result.result();
std::optional<std::vector<uint8_t>> vector_buffer;
vector_buffer = std::vector<uint8_t>(
byte_buffer->begin(), byte_buffer->begin() + vector_size);
result(vector_buffer);
} else {
result(FirebaseStoragePlugin::ParseError(data_result));
}
});
}
Expand Down

0 comments on commit ed8c7c5

Please sign in to comment.