< prev index next >

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

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


 234 
 235 JNIEXPORT jboolean JNICALL Java_sun_awt_windows_ThemeReader_initThemes
 236 (JNIEnv *env, jclass klass) {
 237     static BOOL TryLoadingThemeLib = FALSE;
 238     static BOOL Themed = FALSE;
 239     if (!TryLoadingThemeLib) {
 240         Themed = InitThemes();
 241         TryLoadingThemeLib = TRUE;
 242     }
 243     return JNI_IS_TRUE(Themed);
 244 }
 245 
 246 
 247 
 248 static void assert_result(HRESULT hres, JNIEnv *env) {
 249 #ifdef _DEBUG
 250     if (hres != 0) {
 251         DWORD lastError = GetLastError();
 252         if (lastError != 0) {
 253             LPSTR msgBuffer = NULL;
 254             FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
 255                     FORMAT_MESSAGE_FROM_SYSTEM |
 256                     FORMAT_MESSAGE_IGNORE_INSERTS,
 257                     NULL,
 258                     lastError,
 259                     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
 260                     (LPSTR)&msgBuffer,
 261                     // it's an output parameter when allocate buffer is used
 262                     0,
 263                     NULL);

 264             DTRACE_PRINTLN3("Error: hres=0x%x lastError=0x%x %s\n", hres,
 265                                                 lastError, msgBuffer);





 266         }
 267     }
 268 #endif
 269 }
 270 
 271 
 272 /*
 273  * Class:     sun_awt_windows_ThemeReader
 274  * Method:    openTheme
 275  * Signature: (Ljava/lang/String;)J
 276  */
 277 JNIEXPORT jlong JNICALL Java_sun_awt_windows_ThemeReader_openTheme
 278 (JNIEnv *env, jclass klass, jstring widget) {
 279 
 280     LPCTSTR str = (LPCTSTR) JNU_GetStringPlatformChars(env, widget, NULL);
 281     if (str == NULL) {
 282         JNU_ThrowOutOfMemoryError(env, 0);
 283         return 0;
 284     }
 285     // We need to open the Theme on a Window that will stick around.




 234 
 235 JNIEXPORT jboolean JNICALL Java_sun_awt_windows_ThemeReader_initThemes
 236 (JNIEnv *env, jclass klass) {
 237     static BOOL TryLoadingThemeLib = FALSE;
 238     static BOOL Themed = FALSE;
 239     if (!TryLoadingThemeLib) {
 240         Themed = InitThemes();
 241         TryLoadingThemeLib = TRUE;
 242     }
 243     return JNI_IS_TRUE(Themed);
 244 }
 245 
 246 
 247 
 248 static void assert_result(HRESULT hres, JNIEnv *env) {
 249 #ifdef _DEBUG
 250     if (hres != 0) {
 251         DWORD lastError = GetLastError();
 252         if (lastError != 0) {
 253             LPSTR msgBuffer = NULL;
 254             DWORD fret= FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
 255                     FORMAT_MESSAGE_FROM_SYSTEM |
 256                     FORMAT_MESSAGE_IGNORE_INSERTS,
 257                     NULL,
 258                     lastError,
 259                     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
 260                     (LPSTR)&msgBuffer,
 261                     // it's an output parameter when allocate buffer is used
 262                     0,
 263                     NULL);
 264             if (fret != 0) {
 265                 DTRACE_PRINTLN3("Error: hres=0x%x lastError=0x%x %s\n", hres,
 266                                                 lastError, msgBuffer);
 267                 LocalFree(msgBuffer);
 268             } else {
 269                 DTRACE_PRINTLN2("Error: hres=0x%x lastError=0x%x \n", hres,
 270                                                 lastError);
 271             }
 272         }
 273     }
 274 #endif
 275 }
 276 
 277 
 278 /*
 279  * Class:     sun_awt_windows_ThemeReader
 280  * Method:    openTheme
 281  * Signature: (Ljava/lang/String;)J
 282  */
 283 JNIEXPORT jlong JNICALL Java_sun_awt_windows_ThemeReader_openTheme
 284 (JNIEnv *env, jclass klass, jstring widget) {
 285 
 286     LPCTSTR str = (LPCTSTR) JNU_GetStringPlatformChars(env, widget, NULL);
 287     if (str == NULL) {
 288         JNU_ThrowOutOfMemoryError(env, 0);
 289         return 0;
 290     }
 291     // We need to open the Theme on a Window that will stick around.


< prev index next >