mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8282862: AwtWindow::SetIconData leaks old icon handles if an exception is detected
Reviewed-by: aivanov, dmarkov, prr, honkar, azvegint
This commit is contained in:
parent
356e2a8f48
commit
48ece07214
1 changed files with 39 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -2110,20 +2110,49 @@ done:
|
||||||
void AwtWindow::SetIconData(JNIEnv* env, jintArray iconRaster, jint w, jint h,
|
void AwtWindow::SetIconData(JNIEnv* env, jintArray iconRaster, jint w, jint h,
|
||||||
jintArray smallIconRaster, jint smw, jint smh)
|
jintArray smallIconRaster, jint smw, jint smh)
|
||||||
{
|
{
|
||||||
|
HICON hNewIcon = NULL;
|
||||||
|
HICON hNewIconSm = NULL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
hNewIcon = CreateIconFromRaster(env, iconRaster, w, h);
|
||||||
|
if (env->ExceptionCheck()) {
|
||||||
|
if (hNewIcon != NULL) {
|
||||||
|
DestroyIcon(hNewIcon);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hNewIconSm = CreateIconFromRaster(env, smallIconRaster, smw, smh);
|
||||||
|
if (env->ExceptionCheck()) {
|
||||||
|
if (hNewIcon != NULL) {
|
||||||
|
DestroyIcon(hNewIcon);
|
||||||
|
}
|
||||||
|
if (hNewIconSm != NULL) {
|
||||||
|
DestroyIcon(hNewIconSm);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
if (hNewIcon != NULL) {
|
||||||
|
DestroyIcon(hNewIcon);
|
||||||
|
}
|
||||||
|
if (hNewIconSm != NULL) {
|
||||||
|
DestroyIcon(hNewIconSm);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
HICON hOldIcon = NULL;
|
HICON hOldIcon = NULL;
|
||||||
HICON hOldIconSm = NULL;
|
HICON hOldIconSm = NULL;
|
||||||
//Destroy previous icon if it isn't inherited
|
|
||||||
if ((m_hIcon != NULL) && !m_iconInherited) {
|
if ((m_hIcon != NULL) && !m_iconInherited) {
|
||||||
hOldIcon = m_hIcon;
|
hOldIcon = m_hIcon;
|
||||||
}
|
}
|
||||||
m_hIcon = NULL;
|
|
||||||
if ((m_hIconSm != NULL) && !m_iconInherited) {
|
if ((m_hIconSm != NULL) && !m_iconInherited) {
|
||||||
hOldIconSm = m_hIconSm;
|
hOldIconSm = m_hIconSm;
|
||||||
}
|
}
|
||||||
m_hIconSm = NULL;
|
|
||||||
m_hIcon = CreateIconFromRaster(env, iconRaster, w, h);
|
m_hIcon = hNewIcon;
|
||||||
JNU_CHECK_EXCEPTION(env);
|
m_hIconSm = hNewIconSm;
|
||||||
m_hIconSm = CreateIconFromRaster(env, smallIconRaster, smw, smh);
|
|
||||||
|
|
||||||
m_iconInherited = (m_hIcon == NULL);
|
m_iconInherited = (m_hIcon == NULL);
|
||||||
if (m_iconInherited) {
|
if (m_iconInherited) {
|
||||||
|
@ -2136,8 +2165,11 @@ void AwtWindow::SetIconData(JNIEnv* env, jintArray iconRaster, jint w, jint h,
|
||||||
m_iconInherited = FALSE;
|
m_iconInherited = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DoUpdateIcon();
|
DoUpdateIcon();
|
||||||
EnumThreadWindows(AwtToolkit::MainThread(), UpdateOwnedIconCallback, (LPARAM)this);
|
EnumThreadWindows(AwtToolkit::MainThread(), UpdateOwnedIconCallback, (LPARAM)this);
|
||||||
|
|
||||||
|
// Destroy previous icons if they were not inherited
|
||||||
if (hOldIcon != NULL) {
|
if (hOldIcon != NULL) {
|
||||||
DestroyIcon(hOldIcon);
|
DestroyIcon(hOldIcon);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue