From: Mathieu Chartier Date: Fri, 12 Feb 2016 00:27:18 +0000 (-0800) Subject: Fix app image memory leak X-Git-Tag: android-x86-7.1-r1~412 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=6cc91e4d8c;p=android-x86%2Fart.git Fix app image memory leak There was a memory leak if we failed to add an image space, this was caused by releasing ownership without adding it to the heap. Bug: 22858531 (cherry picked from commit bd064ea2269b23360e32e8139c22d5993ddc385b) Change-Id: Ib45c0140b82cee5da04ed4a9f101f7c554cb25da --- diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc index e76e443cf..18cf81aa7 100644 --- a/runtime/oat_file_manager.cc +++ b/runtime/oat_file_manager.cc @@ -387,12 +387,16 @@ std::vector> OatFileManager::OpenDexFilesFromOat( runtime->GetHeap()->AddSpace(image_space.get()); } added_image_space = true; - if (!runtime->GetClassLinker()->AddImageSpace(image_space.get(), - h_loader, - dex_elements, - dex_location, - /*out*/&dex_files, - /*out*/&temp_error_msg)) { + if (runtime->GetClassLinker()->AddImageSpace(image_space.get(), + h_loader, + dex_elements, + dex_location, + /*out*/&dex_files, + /*out*/&temp_error_msg)) { + // Successfully added image space to heap, release the map so that it does not get + // freed. + image_space.release(); + } else { LOG(INFO) << "Failed to add image file " << temp_error_msg; dex_files.clear(); { @@ -406,7 +410,6 @@ std::vector> OatFileManager::OpenDexFilesFromOat( added_image_space = false; // Non-fatal, don't update error_msg. } - image_space.release(); } } }