-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8282862: AwtWindow::SetIconData leaks old icon handles if an exception is detected #22932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
726fbd9
bdba3a9
79a82de
e22d811
505f804
2f47a55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
|
|
@@ -2110,20 +2110,49 @@ HICON CreateIconFromRaster(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) | ||
| { | ||
| 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 hOldIconSm = NULL; | ||
| //Destroy previous icon if it isn't inherited | ||
| if ((m_hIcon != NULL) && !m_iconInherited) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure why the check for NULL is needed .. but it is OK.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean? That it could've been just This line is unchanged. |
||
| hOldIcon = m_hIcon; | ||
| } | ||
| m_hIcon = NULL; | ||
| if ((m_hIconSm != NULL) && !m_iconInherited) { | ||
| hOldIconSm = m_hIconSm; | ||
| } | ||
| m_hIconSm = NULL; | ||
| m_hIcon = CreateIconFromRaster(env, iconRaster, w, h); | ||
| JNU_CHECK_EXCEPTION(env); | ||
| m_hIconSm = CreateIconFromRaster(env, smallIconRaster, smw, smh); | ||
|
|
||
| m_hIcon = hNewIcon; | ||
| m_hIconSm = hNewIconSm; | ||
|
|
||
| m_iconInherited = (m_hIcon == NULL); | ||
| if (m_iconInherited) { | ||
|
|
@@ -2136,8 +2165,11 @@ void AwtWindow::SetIconData(JNIEnv* env, jintArray iconRaster, jint w, jint h, | |
| m_iconInherited = FALSE; | ||
| } | ||
| } | ||
|
|
||
| DoUpdateIcon(); | ||
| EnumThreadWindows(AwtToolkit::MainThread(), UpdateOwnedIconCallback, (LPARAM)this); | ||
|
|
||
| // Destroy previous icons if they were not inherited | ||
| if (hOldIcon != NULL) { | ||
| DestroyIcon(hOldIcon); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume we know for sure there's no exception pending when we enter ?
Looking at the only caller, it seems probable.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting we add a JNU_CHECK_EXCEPTION the beginning of the function? , as I don't think we know for sure there is an exception pending or not at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There can't be a pending exception when
AwtWindow::SetIconDatastarts.The chain starts with JNI method
Java_sun_awt_windows_WWindowPeer_setIconImagesDatawhich callsAwtWindow::_SetIconImagesDatawrapped inSyncCall.No Java code is called before execution gets into
SetIconDatawhereCreateIconFromRasteris called.I'm sure there's no pending exception on the entry to
AwtWindow::SetIconData.