[AIX][PGO] Add malloc error handling and deallocation to FindBinaryId function
authorWael Yehia <wyehia@ca.ibm.com>
Tue, 4 Apr 2023 19:28:21 +0000 (19:28 +0000)
committerWael Yehia <wyehia@ca.ibm.com>
Tue, 4 Apr 2023 19:57:40 +0000 (19:57 +0000)
This is a follow up on D146976.

Reviewed By: stephenpeckham

Differential Revision: https://reviews.llvm.org/D147559

compiler-rt/lib/profile/InstrProfilingPlatformAIX.c

index ce03766..6e12fb9 100644 (file)
@@ -38,11 +38,12 @@ static size_t FindBinaryId(char *Result, size_t Size) {
   if (RC == -1 && errno == ENOMEM) {
     BufSize = 64000; // should be plenty for any program.
     BufPtr = malloc(BufSize);
-    RC = loadquery(L_GETXINFO | L_IGNOREUNLOAD, BufPtr, (unsigned int)BufSize);
+    if (BufPtr != 0)
+      RC = loadquery(L_GETXINFO | L_IGNOREUNLOAD, BufPtr, (unsigned int)BufSize);
   }
 
   if (RC == -1)
-    return RC;
+    goto done;
 
   // Locate the ld_xinfo corresponding to this module.
   struct ld_xinfo *CurInfo = (struct ld_xinfo *)BufPtr;