From 16382634fcc1c850b7c3b8f9646ac122bea818a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Kongstad?= Date: Thu, 2 Jun 2016 09:35:09 +0200 Subject: [PATCH 1/2] installd: add command 'removeIdmap' Add an installd command to remove an idmap file. This is the inverse of the 'idmap' command and is intended for clean-up once an idmap file is no longer needed because an APK was removed, etc. This commit depends on a corresponding commit in frameworks/native (with the same Change-Id). Bug: 31052947 Test: run tests from 'OMS: tests for OverlayManagerService' Change-Id: Iae19a519803f0c172b02a32faa283ef36f43863c --- services/core/java/com/android/server/pm/Installer.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services/core/java/com/android/server/pm/Installer.java b/services/core/java/com/android/server/pm/Installer.java index 0130e300dd8b3..fc66bb3d6130c 100644 --- a/services/core/java/com/android/server/pm/Installer.java +++ b/services/core/java/com/android/server/pm/Installer.java @@ -295,6 +295,15 @@ public class Installer extends SystemService { } } + public void removeIdmap(String overlayApkPath) throws InstallerException { + if (!checkBeforeRemote()) return; + try { + mInstalld.removeIdmap(overlayApkPath); + } catch (Exception e) { + throw InstallerException.from(e); + } + } + public void rmdex(String codePath, String instructionSet) throws InstallerException { assertValidInstructionSet(instructionSet); if (!checkBeforeRemote()) return; From 6bb13da2789b2485a628e4fc077524b430661c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Kongstad?= Date: Thu, 2 Jun 2016 09:34:36 +0200 Subject: [PATCH 2/2] Fix memory leak during idmap creation Plug a memory leak in AssetManager::createIdmap. Bug: 31052947 Test: use Valgrind and dummy native app Change-Id: I83af3a40516ed2d50d5a7c8ee175ed960fde9933 --- libs/androidfw/AssetManager.cpp | 36 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp index e0689006d5dda..acacd7654cf1b 100644 --- a/libs/androidfw/AssetManager.cpp +++ b/libs/androidfw/AssetManager.cpp @@ -288,22 +288,34 @@ bool AssetManager::createIdmap(const char* targetApkPath, const char* overlayApk { AutoMutex _l(mLock); const String8 paths[2] = { String8(targetApkPath), String8(overlayApkPath) }; - ResTable tables[2]; + Asset* assets[2] = {NULL, NULL}; + bool ret = false; + { + ResTable tables[2]; - for (int i = 0; i < 2; ++i) { - asset_path ap; - ap.type = kFileTypeRegular; - ap.path = paths[i]; - Asset* ass = openNonAssetInPathLocked("resources.arsc", Asset::ACCESS_BUFFER, ap); - if (ass == NULL) { - ALOGW("failed to find resources.arsc in %s\n", ap.path.string()); - return false; + for (int i = 0; i < 2; ++i) { + asset_path ap; + ap.type = kFileTypeRegular; + ap.path = paths[i]; + assets[i] = openNonAssetInPathLocked("resources.arsc", + Asset::ACCESS_BUFFER, ap); + if (assets[i] == NULL) { + ALOGW("failed to find resources.arsc in %s\n", ap.path.string()); + goto exit; + } + if (tables[i].add(assets[i]) != NO_ERROR) { + ALOGW("failed to add %s to resource table", paths[i].string()); + goto exit; + } } - tables[i].add(ass); + ret = tables[0].createIdmap(tables[1], targetCrc, overlayCrc, + targetApkPath, overlayApkPath, (void**)outData, outSize) == NO_ERROR; } - return tables[0].createIdmap(tables[1], targetCrc, overlayCrc, - targetApkPath, overlayApkPath, (void**)outData, outSize) == NO_ERROR; +exit: + delete assets[0]; + delete assets[1]; + return ret; } bool AssetManager::addDefaultAssets()