changeset 52901:8b066aaff367

8213532: add missing LocalFree calls after using FormatMessage(A) [windows] Reviewed-by: dmarkov, serb
author mbaesken
date Thu, 08 Nov 2018 17:10:47 +0100
parents ff49d3fcb934
children 83de6a8b6c33
files src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp src/java.desktop/windows/native/libawt/windows/awt_Debug.cpp src/jdk.accessibility/windows/native/common/AccessBridgeDebug.cpp
diffstat 3 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp	Wed Nov 14 18:27:51 2018 +0530
+++ b/src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp	Thu Nov 08 17:10:47 2018 +0100
@@ -251,7 +251,7 @@
         DWORD lastError = GetLastError();
         if (lastError != 0) {
             LPSTR msgBuffer = NULL;
-            FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+            DWORD fret= FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
                     FORMAT_MESSAGE_FROM_SYSTEM |
                     FORMAT_MESSAGE_IGNORE_INSERTS,
                     NULL,
@@ -261,8 +261,14 @@
                     // it's an output parameter when allocate buffer is used
                     0,
                     NULL);
-            DTRACE_PRINTLN3("Error: hres=0x%x lastError=0x%x %s\n", hres,
+            if (fret != 0) {
+                DTRACE_PRINTLN3("Error: hres=0x%x lastError=0x%x %s\n", hres,
                                                 lastError, msgBuffer);
+                LocalFree(msgBuffer);
+            } else {
+                DTRACE_PRINTLN2("Error: hres=0x%x lastError=0x%x \n", hres,
+                                                lastError);
+            }
         }
     }
 #endif
--- a/src/java.desktop/windows/native/libawt/windows/awt_Debug.cpp	Wed Nov 14 18:27:51 2018 +0530
+++ b/src/java.desktop/windows/native/libawt/windows/awt_Debug.cpp	Thu Nov 08 17:10:47 2018 +0100
@@ -182,7 +182,7 @@
     int     ret = IDNO;
     static jboolean headless = isHeadless();
 
-    FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+    DWORD fret= FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
                   FORMAT_MESSAGE_FROM_SYSTEM |
                   FORMAT_MESSAGE_IGNORE_INSERTS,
                   NULL,
@@ -197,7 +197,9 @@
     }
     // format the assertion message
     _snprintf(assertMsg, ASSERT_MSG_SIZE, AssertFmt, expr, file, line, lastError, msgBuffer);
-    LocalFree(msgBuffer);
+    if (fret != 0) {
+        LocalFree(msgBuffer);
+    }
 
     // tell the user the bad news
     fprintf(stderr, "*********************\n");
--- a/src/jdk.accessibility/windows/native/common/AccessBridgeDebug.cpp	Wed Nov 14 18:27:51 2018 +0530
+++ b/src/jdk.accessibility/windows/native/common/AccessBridgeDebug.cpp	Thu Nov 08 17:10:47 2018 +0100
@@ -66,6 +66,7 @@
     if (lpMsgBuf != NULL) {
         strncat((char *)retbuf, ": ", sizeof(retbuf) - strlen(retbuf) - 1);
         strncat((char *)retbuf, (char *)lpMsgBuf, sizeof(retbuf) - strlen(retbuf) - 1);
+        LocalFree(lpMsgBuf);
     }
     return (char *)retbuf;
 }