From 1fae45f7d777e3971b916dda531c8648304866c8 Mon Sep 17 00:00:00 2001 From: Calin Juravle Date: Tue, 8 Mar 2016 12:52:52 +0000 Subject: [PATCH] Handle unexpected cases in profile saver There are some unexpected cases that should not occur in a normal run. Log warnings but avoid crashing if: - dex location is empty - we cannot figure the real paths of the locations. Bug: 27532729 Change-Id: I2c9ee8d616378d1d6f771b071f61321a2916ce27 --- runtime/jit/profile_saver.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/runtime/jit/profile_saver.cc b/runtime/jit/profile_saver.cc index 8dc696fca..6fe17dbe1 100644 --- a/runtime/jit/profile_saver.cc +++ b/runtime/jit/profile_saver.cc @@ -303,13 +303,22 @@ void ProfileSaver::MaybeRecordDexUseInternal( const std::set& app_code_paths, const std::string& foreign_dex_profile_path, const std::string& app_data_dir) { + if (dex_location.empty()) { + LOG(WARNING) << "Asked to record foreign dex use with an empty dex location."; + return; + } if (foreign_dex_profile_path.empty()) { LOG(WARNING) << "Asked to record foreign dex use without a valid profile path "; return; } UniqueCPtr dex_location_real_path(realpath(dex_location.c_str(), nullptr)); - std::string dex_location_real_path_str(dex_location_real_path.get()); + if (dex_location_real_path == nullptr) { + PLOG(WARNING) << "Could not get realpath for " << dex_location; + } + std::string dex_location_real_path_str((dex_location_real_path == nullptr) + ? dex_location.c_str() + : dex_location_real_path.get()); if (dex_location_real_path_str.compare(0, app_data_dir.length(), app_data_dir) == 0) { // The dex location is under the application folder. Nothing to record. @@ -327,7 +336,12 @@ void ProfileSaver::MaybeRecordDexUseInternal( // to save some bytes of memory usage. for (const auto& app_code_location : app_code_paths) { UniqueCPtr real_app_code_location(realpath(app_code_location.c_str(), nullptr)); - std::string real_app_code_location_str(real_app_code_location.get()); + if (real_app_code_location == nullptr) { + PLOG(WARNING) << "Could not get realpath for " << app_code_location; + } + std::string real_app_code_location_str((real_app_code_location == nullptr) + ? app_code_location.c_str() + : real_app_code_location.get()); if (real_app_code_location_str == dex_location_real_path_str) { // The dex location belongs to the application code paths. Nothing to record. return; -- 2.11.0