diff options
author | MÃ¥rten Kongstad <marten.kongstad@sonymobile.com> | 2016-06-02 09:34:36 +0200 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2017-01-24 20:26:51 -0800 |
commit | 6bb13da2789b2485a628e4fc077524b430661c82 (patch) | |
tree | 9e4b3765df56ebc451b3e2a77f007b6f5a055811 /libs/androidfw/AssetManager.cpp | |
parent | 16382634fcc1c850b7c3b8f9646ac122bea818a1 (diff) |
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
Diffstat (limited to 'libs/androidfw/AssetManager.cpp')
-rw-r--r-- | libs/androidfw/AssetManager.cpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp index e0689006d5dd..acacd7654cf1 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]; - - 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; + 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]; + 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() |