Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

frameworks-base: Commit

frameworks/base


Commit MetaInfo

Revisión9983b4dadf91a21d72985f9e6a22c064bf374cfa (tree)
Tiempo2019-11-14 13:55:28
Autorjgu21 <jinghui.gu@inte...>
CommiterChih-Wei Huang

Log Message

Fix the memory leak bug introduced by PRC compatibility feature

Fix the memory leak bug introduced by PRC compatibility feature,
introduced by https://android.intel.com/#/c/471490/

Change-Id: Iaf9bd21afa17f3a81ab700c63ae7c0bb0851a594
Tracked-On: https://jira01.devtools.intel.com/browse/OAM-27449
Signed-off-by: jgu21 <jinghui.gu@intel.com>
Reviewed-on: https://android.intel.com:443/489353

Cambiar Resumen

Diferencia incremental

--- a/core/jni/abipicker/ABIPicker.cpp
+++ b/core/jni/abipicker/ABIPicker.cpp
@@ -10,14 +10,15 @@ namespace android {
1010 #define ARR_SIZE(x) (sizeof(x)/sizeof(x[0]))
1111
1212 #define SO_NAME_MAX (4096)
13+
1314 #define IMPOSSIBLE_LIB_NAME "/mixed/"
1415 #define IMPOSSIBLE_LIB_LEN (sizeof(IMPOSSIBLE_LIB_NAME)-1)
16+
1517 #define ARMABI "armeabi"
1618 #define ARMV7ABI "armeabi-v7a"
1719 #define ARM64ABI "arm64-v8a"
1820 #define X86ABI "x86"
1921 #define X8664ABI "x86_64"
20-#define ARMABI_NAME_PREFIX "arm"
2122
2223 #define APK_LIB "lib/"
2324 #define APK_LIB_LEN (sizeof(APK_LIB) - 1)
@@ -28,9 +29,10 @@ namespace android {
2829 #define P_LOG(...)
2930 #endif
3031
31-#define OEMWHITE "/vendor/etc/misc/.OEMWhiteList"
32-#define OEMBLACK "/vendor/etc/misc/.OEMBlackList"
33-#define THIRDPARTY "/vendor/etc/misc/.ThirdPartySO"
32+#define LISTPATH "/vendor/etc/misc/"
33+#define OEMWHITE LISTPATH ".OEMWhiteList"
34+#define OEMBLACK LISTPATH ".OEMBlackList"
35+#define THIRDPARTY LISTPATH ".ThirdPartySO"
3436
3537 // load once, hold until poweroff
3638 static Vector <char*> thirdPartySO;
@@ -42,7 +44,18 @@ static bool blackload = false;
4244
4345 static const char* iaRelated[] = {"intel", "intl", "atom", "x86", "x64"};
4446
45-//////////////////////////////////////////////////////////////////////
47+void freeAllString(Vector<char*>& list) {
48+ Vector<char*>::iterator it = list.begin();
49+ while (it != list.end()) {
50+ if (*it != NULL) {
51+ P_LOG("freeAllSring %p , %s", it, *it);
52+ free(*it);
53+ *it = NULL;
54+ }
55+ it++;
56+ }
57+}
58+
4659 void getConfig(const char* cfgFile , Vector<char*>& cfgVec) {
4760 int read = -1;
4861 char *line = NULL;
@@ -53,10 +66,13 @@ void getConfig(const char* cfgFile , Vector<char*>& cfgVec) {
5366 return;
5467 }
5568
69+ freeAllString(cfgVec);
70+ cfgVec.clear();
71+
5672 while ((read = getline(&line, &len, fp)) != -1) {
5773 int i = 0 , j = 0;
5874 char *cfgline = (char*)malloc(len);
59- if (!cfgline) {
75+ if (cfgline == NULL) {
6076 P_LOG("malloc error");
6177 break;
6278 }
@@ -73,23 +89,11 @@ void getConfig(const char* cfgFile , Vector<char*>& cfgVec) {
7389 fclose(fp);
7490 }
7591
76-//////////////////////////////////////////////////////////////////////
77-void freeAllString(Vector<char*>& list) {
78- Vector<char*>::iterator it = list.begin();
79- while (it != list.end()) {
80- if (*it != NULL) {
81- P_LOG("freeAllSring %p , %s", it, *it);
82- free(*it);
83- *it = NULL;
84- }
85- it++;
86- }
87-}
88-
89-//////////////////////////////////////////////////////////////////////
9092 bool isInOEMWhiteList(const char* pkgName) {
9193 bool result = false;
92- if (!pkgName) return result;
94+ if (pkgName == NULL) {
95+ return result;
96+ }
9397
9498 if (!whiteload) {
9599 getConfig(OEMWHITE, cfgWhite);
@@ -108,10 +112,11 @@ bool isInOEMWhiteList(const char* pkgName) {
108112 return result;
109113 }
110114
111-//////////////////////////////////////////////////////////////////////
112115 bool isInOEMBlackList(const char* pkgName) {
113116 bool result = false;
114- if (!pkgName) return result;
117+ if (pkgName == NULL) {
118+ return result;
119+ }
115120
116121 if (!blackload) {
117122 getConfig(OEMBLACK, cfgBlack);
@@ -129,8 +134,6 @@ bool isInOEMBlackList(const char* pkgName) {
129134 return result;
130135 }
131136
132-
133-//////////////////////////////////////////////////////////////////////
134137 bool isReliableLib(Vector<char*>& libList) {
135138 unsigned sz = libList.size();
136139 int len = ARR_SIZE(iaRelated);
@@ -151,8 +154,6 @@ bool isReliableLib(Vector<char*>& libList) {
151154 return false;
152155 }
153156
154-
155-//////////////////////////////////////////////////////////////////////
156157 static bool isValidELF(char* buffer) {
157158 if (buffer[EI_MAG0] != ELFMAG0 &&
158159 buffer[EI_MAG1] != ELFMAG1 &&
@@ -169,11 +170,13 @@ static bool isMixedLib(char* libCur, char* buffer) {
169170 uint16_t machine_code = *((uint16_t*)(&buffer[ELF_MACHINE_OFFSET]));
170171 bool mixed = false;
171172 if (isX86_64) {
172- if (machine_code != EM_X86_64)
173+ if (machine_code != EM_X86_64) {
173174 mixed = true;
175+ }
174176 } else {
175- if (machine_code != EM_386)
177+ if (machine_code != EM_386) {
176178 mixed = true;
179+ }
177180 }
178181 return mixed;
179182 }
@@ -201,6 +204,7 @@ static bool isInThirdPartySOList(char* libName) {
201204 size_t sz = thirdPartySO.size();
202205 for (size_t i = 0; i < sz; i++) {
203206 // thirdPartySO[i] won't be NULL
207+ assert(thirdPartySO[i] != NULL);
204208 size_t n = strlen(thirdPartySO[i]);
205209 // three char for ".so"
206210 int j = libLen - 4;
@@ -225,9 +229,8 @@ static void insertionSort(Vector<char*>& list) {
225229 P_LOG("in insertionSort, list size = %d\n", list.size());
226230
227231 for (size_t i = 1; i < list.size(); i++) {
228- char* x = list[i];
229-
230232 int j = i - 1;
233+ char* x = list[i];
231234 P_LOG("sort 1. x=%s, i=%d, j=%d\n", x, i, j);
232235 while (j >= 0 && (strcmp(list[j], x) > 0)) {
233236 list.replaceAt(list[j], j + 1);
@@ -237,9 +240,6 @@ static void insertionSort(Vector<char*>& list) {
237240 }
238241 }
239242
240-
241-
242-//////////////////////////////////////////////////////////////////////
243243 // Use armRef as a reference, compare all libraries of iaRef with all
244244 // libraries of armRef.If the two are match or iaRef is more, iaRef
245245 // will be returned with *result and true is return value. Or else,
@@ -392,7 +392,9 @@ bool ABIPicker::compare3rdPartyLibList(
392392 }
393393 result = compareLibList(*iaRef3rdPartyLibList, *armRef3rdPartyLibList);
394394
395+ armRef3rdPartyLibList->clear();
395396 delete armRef3rdPartyLibList;
397+ iaRef3rdPartyLibList->clear();
396398 delete iaRef3rdPartyLibList;
397399 return result;
398400 }
@@ -451,9 +453,9 @@ Vector<char*>* ABIPicker::getLibList(const char* abiName) {
451453 }
452454
453455
454-size_t ABIPicker::getSpecficABILibCount(const char* abiName) {
456+bool ABIPicker::isABILibValid(const char* abiName) {
455457 Vector<char*>* specificAbiLibList = getLibList(abiName);
456- return specificAbiLibList && specificAbiLibList->size();
458+ return ((specificAbiLibList && specificAbiLibList->size()) > 0);
457459 }
458460
459461 bool ABIPicker::foundMixedELF(const char* abiName) {
@@ -472,12 +474,10 @@ bool ABIPicker::foundMixedELF(const char* abiName) {
472474 return true;
473475 }
474476
475-
476-//////////////////////////////////////////////////////////////////////
477477 ABIPicker::ABIPicker(const char* pkgName, Vector<ScopedUtfChars*> abiList) {
478478 mLibList = new Vector<struct libInfo*>();
479479 mpkgName = strdup(pkgName);
480- if (!mpkgName) {
480+ if (mpkgName == NULL) {
481481 P_LOG("ABIPicker Construct Allocated space fails");
482482 }
483483 Vector<ScopedUtfChars*>::iterator it = abiList.begin();
@@ -488,7 +488,7 @@ ABIPicker::ABIPicker(const char* pkgName, Vector<ScopedUtfChars*> abiList) {
488488
489489 struct libInfo* tmp = (struct libInfo*)calloc(1,
490490 sizeof(struct libInfo));
491- if (!tmp) {
491+ if (tmp == NULL) {
492492 P_LOG("ABIPicker Construct Allocated space fail %s", (*it)->c_str());
493493 break;
494494 }
@@ -517,13 +517,13 @@ ABIPicker::~ABIPicker(void) {
517517 it++;
518518 }
519519 mLibList->clear();
520- delete(mLibList);
520+ delete mLibList;
521521 }
522522
523523 bool ABIPicker::buildNativeLibList(void* apkHandle) {
524524 bool ret = false;
525525
526- if (!apkHandle) {
526+ if (apkHandle == NULL) {
527527 ALOGE("apkHandle is NULL\n");
528528 return ret;
529529 }
@@ -570,7 +570,7 @@ bool ABIPicker::buildNativeLibList(void* apkHandle) {
570570 unCompBuff = NULL;
571571
572572 unCompBuff = (char*)malloc(unCompLen);
573- if (!unCompBuff) {
573+ if (unCompBuff == NULL) {
574574 ALOGE("malloc failed size %d\n", unCompLen);
575575 ret = false;
576576 break;
@@ -683,50 +683,49 @@ int ABIPicker::pickupRightABI(int sysPrefer) {
683683 bool x8664HasMixedELF = foundMixedELF(X8664ABI);
684684 bool x86HasMixedELF = foundMixedELF(X86ABI);
685685
686- size_t armv7LibCount = getSpecficABILibCount(ARMV7ABI);
687- size_t armv5LibCount = getSpecficABILibCount(ARMABI);
688- size_t armv8LibCount = getSpecficABILibCount(ARM64ABI);
689- size_t x86LibCount = x86HasMixedELF ? 0 : getSpecficABILibCount(X86ABI);
690- size_t x8664LibCount = x8664HasMixedELF ? 0 : getSpecficABILibCount(X8664ABI);
691- P_LOG("armv7LibCount:%d armv5LibCount:%d armv8LibCount:%d x86LibCount:%d x8664LibCount:%d", armv7LibCount, armv5LibCount, armv8LibCount, x86LibCount, x8664LibCount);
686+ bool armv7LibValid = isABILibValid(ARMV7ABI);
687+ bool armv5LibValid = isABILibValid(ARMABI);
688+ bool armv8LibValid = isABILibValid(ARM64ABI);
689+ bool x86LibValid = x86HasMixedELF ? 0 : isABILibValid(X86ABI);
690+ bool x8664LibValid = x8664HasMixedELF ? 0 : isABILibValid(X8664ABI);
692691
693692 // in OEMBlackList, need to be supported by bt
694693 // but in case of armlib doesn't exist, we choose x86 or x86_64
695694 if (isInOEMBlackList(mpkgName)) {
696- if (armv7LibCount > 0) {
695+ if (armv7LibValid) {
697696 return getAbiIndex(ARMV7ABI);
698- } else if (armv5LibCount > 0) {
697+ } else if (armv5LibValid) {
699698 return getAbiIndex(ARMABI);
700- } else if (armv8LibCount > 0) {
699+ } else if (armv8LibValid) {
701700 return getAbiIndex(ARM64ABI);
702701 }
703702 }
704703
705704 char arm64Ref[ABI_NAME_MAX_LENGTH];
706- if (armv8LibCount > 0) {
705+ if (armv8LibValid) {
707706 snprintf(arm64Ref, sizeof(ARM64ABI), "%s", ARM64ABI);
708707 } else {
709708 arm64Ref[0] = '\0';
710709 }
711710
712711 char arm32Ref[ABI_NAME_MAX_LENGTH];
713- if (armv7LibCount > 0) {
712+ if (armv7LibValid) {
714713 snprintf(arm32Ref, sizeof(ARMV7ABI), "%s", ARMV7ABI);
715- } else if (armv5LibCount > 0) {
714+ } else if (armv5LibValid) {
716715 snprintf(arm32Ref, sizeof(ARMABI), "%s", ARMABI);
717716 } else {
718717 arm32Ref[0] = '\0';
719718 }
720719
721720 char ia32Ref[ABI_NAME_MAX_LENGTH];
722- if (x86LibCount > 0) {
721+ if (x86LibValid) {
723722 snprintf(ia32Ref, sizeof(X86ABI), "%s", X86ABI);
724723 } else {
725724 ia32Ref[0] = '\0';
726725 }
727726
728727 char ia64Ref[ABI_NAME_MAX_LENGTH];
729- if (x8664LibCount > 0) {
728+ if (x8664LibValid) {
730729 snprintf(ia64Ref, ABI_NAME_MAX_LENGTH, "%s", X8664ABI);
731730 } else {
732731 ia64Ref[0] = '\0';
--- a/core/jni/abipicker/ABIPicker.h
+++ b/core/jni/abipicker/ABIPicker.h
@@ -12,17 +12,6 @@ namespace android {
1212 // assumption: the length of name of any abi type in abi list,
1313 // like armeabi-v7a, armeabi, x86, is not longer than 64
1414 #define ABI_NAME_MAX_LENGTH (64)
15-/*
16-class LibInfo {
17- public:
18- LibInfo(char* s, List<char*> list);
19- ~LibInfo(void);
20-
21- private:
22- char abiName[ABI_NAME_MAX_LENGTH];
23- List<char*> libNameList;
24-};
25-*/
2615
2716 class ABIPicker {
2817 public:
@@ -46,7 +35,7 @@ class ABIPicker {
4635 size_t* iaIsvLibCount, size_t* armIsvLibCount);
4736 char* getAbiName(int abi);
4837 int getAbiIndex(const char* abiName);
49- size_t getSpecficABILibCount(const char* abiName);
38+ bool isABILibValid(const char* abiName);
5039 Vector<char*>* getLibList(const char* abiName);
5140 };
5241
--- a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
+++ b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
@@ -543,30 +543,34 @@ com_android_internal_content_NativeLibraryHelper_findSupportedAbi_replace(
543543 return (jint)abiType;
544544 }
545545
546+ int abiIndex = 0;
546547 abiFlag[apkdir_size] = '/';
547548 abiFlag[apkdir_size + 1] = '.';
548- for (int i = 0; i < numAbis; i++) {
549+ for (abiIndex = 0; abiIndex < numAbis; abiIndex++) {
549550 ScopedUtfChars* abiName = new ScopedUtfChars(env,
550- (jstring)env->GetObjectArrayElement(javaCpuAbisToSearch, i));
551- assert(abiName != NULL);
552- assert(abiName->c_str() != NULL);
553- if (strlcpy(abiFlag + apkdir_size + 2, abiName->c_str(), 256 - apkdir_size - 2)
554- == abiName->size()) {
555- if (access(abiFlag, F_OK) == 0) {
556- abiType = i;
557- for (int j = 0; j < i; ++j) {
558- delete supportedAbis[j];
559- }
560- delete abiName;
561- return (jint)abiType;
562- }
551+ (jstring)env->GetObjectArrayElement(javaCpuAbisToSearch, abiIndex));
552+ supportedAbis.push_back(abiName);
553+ if (abiName == NULL || abiName->c_str() == NULL || abiName->size() <= 0) {
554+ break;
555+ }
556+ if ((strlcpy(abiFlag + apkdir_size + 2, abiName->c_str(), 256 - apkdir_size - 2)
557+ == abiName->size()) && (access(abiFlag, F_OK) == 0)) {
558+ abiType = abiIndex;
559+ break;
563560 }
561+ }
564562
565- supportedAbis.push_back(abiName);
563+ if (abiIndex < numAbis) {
564+ for (int j = 0; j < abiIndex; ++j) {
565+ if (supportedAbis[j] != NULL) {
566+ delete supportedAbis[j];
567+ }
568+ }
569+ return (jint)abiType;
566570 }
567571
568572 do {
569- if (abiType < 0 || abiType >= numAbis ) {
573+ if (abiType < 0 || abiType >= numAbis) {
570574 break;
571575 }
572576
@@ -593,7 +597,10 @@ com_android_internal_content_NativeLibraryHelper_findSupportedAbi_replace(
593597 if (abiType >= 0 && abiType < numAbis &&
594598 (strlcpy(abiFlag + apkdir_size + 2, supportedAbis[abiType]->c_str(),
595599 256 - apkdir_size - 2) == supportedAbis[abiType]->size())) {
596- creat(abiFlag, 0644);
600+ int flagFp = creat(abiFlag, 0644);
601+ if (flagFp != -1) {
602+ close(flagFp);
603+ }
597604 }
598605
599606 } while(0);
Show on old repository browser