< prev index next >

src/java.desktop/windows/native/libawt/windows/awt_Debug.cpp

Print this page
rev 52446 : 8213532: add missing LocalFree calls after using FormatMessage(A) [windows]

@@ -180,11 +180,11 @@
     DWORD   lastError = GetLastError();
     LPSTR       msgBuffer = NULL;
     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,
                   lastError,
                   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),

@@ -195,11 +195,13 @@
     if (msgBuffer == NULL) {
         msgBuffer = "<Could not get GetLastError() message text>";
     }
     // format the assertion message
     _snprintf(assertMsg, ASSERT_MSG_SIZE, AssertFmt, expr, file, line, lastError, msgBuffer);
+    if (fret != 0) {
     LocalFree(msgBuffer);
+    }
 
     // tell the user the bad news
     fprintf(stderr, "*********************\n");
     fprintf(stderr, "AWT Assertion Failure\n");
     fprintf(stderr, "*********************\n");
< prev index next >