diff --git a/shell/platform/android/flutter_main.cc b/shell/platform/android/flutter_main.cc index 50a82da78901d..75b3ada070829 100644 --- a/shell/platform/android/flutter_main.cc +++ b/shell/platform/android/flutter_main.cc @@ -104,33 +104,27 @@ void ConfigureShorebird(std::string android_cache_path, fml::CreateDirectory(fml::paths::GetCachesDirectory(), {"shorebird_updater"}, fml::FilePermission::kReadWrite); - AppParameters app_parameters; - app_parameters.release_version = version.c_str(); - app_parameters.cache_dir = cache_dir.c_str(); - - // Converting the strings in `settings.application_library_path` to `char*`. - // We maintain a separate vector so that the lifetime of the `char*` is clear. - // If we used `c_str` then we would have to be very careful not to modify the - // string or have taken a copy of the string as `c_str` is only valid for the - // lifetime of the string. - std::vector> libapp_paths_storage; - std::vector original_libapp_paths; - for (auto& path : settings.application_library_path) { - libapp_paths_storage.push_back(std::vector(path.begin(), path.end())); - original_libapp_paths.push_back(libapp_paths_storage.back().data()); - } + // Using a block to make AppParameters lifetime explicit. + { + AppParameters app_parameters; + app_parameters.release_version = version.c_str(); + app_parameters.cache_dir = cache_dir.c_str(); + + // https://stackoverflow.com/questions/26032039/convert-vectorstring-into-char-c + std::vector c_paths{}; + for (const auto& string : settings.application_library_path) { + c_paths.push_back(string.c_str()); + } + // Do not modify application_library_path or c_strings will invalidate. - app_parameters.original_libapp_paths = original_libapp_paths.data(); - app_parameters.original_libapp_paths_size = original_libapp_paths.size(); + app_parameters.original_libapp_paths = c_paths.data(); + app_parameters.original_libapp_paths_size = c_paths.size(); - // TODO: How do can we get the path to libflutter.so? - // The Rust side doesn't actually use this yet. The intent is so - // that Rust could hash it, or otherwise know that it matches the - // version the patch is intended for, but currently that's not - // implemented. - app_parameters.vm_path = "libflutter.so"; + app_parameters.vm_path = "libflutter.so"; // Unused. - shorebird_init(&app_parameters, shorebirdYaml.c_str()); + // shorebird_init copies from app_parameters and shorebirdYaml. + shorebird_init(&app_parameters, shorebirdYaml.c_str()); + } FML_LOG(INFO) << "Starting Shorebird update"; shorebird_update();