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
(cherry picked from commit 1fae45f7d777e3971b916dda531c8648304866c8)
Change-Id: I9e8f4fc2da49f47dab113795ac264c6db9b691de
diff --git a/runtime/jit/profile_saver.cc b/runtime/jit/profile_saver.cc
index 5abfa6c..7f014fb 100644
--- a/runtime/jit/profile_saver.cc
+++ b/runtime/jit/profile_saver.cc
@@ -301,13 +301,22 @@
const std::set<std::string>& 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<const char[]> 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.
@@ -325,7 +334,12 @@
// to save some bytes of memory usage.
for (const auto& app_code_location : app_code_paths) {
UniqueCPtr<const char[]> 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;