Previously, ImmGenerateMessage could return early when ImmLockIMCC(ctx->hMsgBuf) failed, without unlocking the HIMC obtained via ImmLockIMC. This could leave the HIMC locked and lead to resource leaks.
This patch adds calls to ImmUnlockIMC(himc) at all early return points, and also unlocks the HIMC before returning TRUE at the end, ensuring that every ImmLockIMC call is properly balanced with a corresponding ImmUnlockIMC.
Tested on: Ubuntu 25.10 & deepin Linux V25, Wine compiled from master branch. No functional behavior of message dispatch is changed.
Signed-off-by: chenzhengyong chenzhengyong@uniontech.com
From: chenzhengyong chenzhengyong@uniontech.com
Signed-off-by: chenzhengyong chenzhengyong@uniontech.com --- dlls/imm32/imm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/dlls/imm32/imm.c b/dlls/imm32/imm.c index 1d5b8cd8fa3..38ec0facff9 100644 --- a/dlls/imm32/imm.c +++ b/dlls/imm32/imm.c @@ -3073,13 +3073,18 @@ BOOL WINAPI ImmGenerateMessage( HIMC himc ) while (ctx->dwNumMsgBuf--) { TRANSMSG *msgs, msg; - if (!(msgs = ImmLockIMCC( ctx->hMsgBuf ))) return FALSE; + if (!(msgs = ImmLockIMCC( ctx->hMsgBuf ))) + { + ImmUnlockIMC( himc); + return FALSE; + } msg = msgs[0]; memmove( msgs, msgs + 1, ctx->dwNumMsgBuf * sizeof(*msgs) ); ImmUnlockIMCC( ctx->hMsgBuf ); SendMessageW( ctx->hWnd, msg.message, msg.wParam, msg.lParam ); } ctx->dwNumMsgBuf++; + ImmUnlockIMC( himc);
return TRUE; }
Rémi Bernon (@rbernon) commented about dlls/imm32/imm.c:
while (ctx->dwNumMsgBuf--) { TRANSMSG *msgs, msg;
if (!(msgs = ImmLockIMCC( ctx->hMsgBuf ))) return FALSE;
if (!(msgs = ImmLockIMCC( ctx->hMsgBuf )))
{
ImmUnlockIMC( himc);
return FALSE;
} ctx->dwNumMsgBuf++;} msg = msgs[0]; memmove( msgs, msgs + 1, ctx->dwNumMsgBuf * sizeof(*msgs) ); ImmUnlockIMCC( ctx->hMsgBuf ); SendMessageW( ctx->hWnd, msg.message, msg.wParam, msg.lParam );
- ImmUnlockIMC( himc);
```suggestion:-11+0 if (!(msgs = ImmLockIMCC( ctx->hMsgBuf ))) { ImmUnlockIMC( himc ); return FALSE; } msg = msgs[0]; memmove( msgs, msgs + 1, ctx->dwNumMsgBuf * sizeof(*msgs) ); ImmUnlockIMCC( ctx->hMsgBuf ); SendMessageW( ctx->hWnd, msg.message, msg.wParam, msg.lParam ); } ctx->dwNumMsgBuf++; ImmUnlockIMC( himc ); ```
Please keep the spacing consistent. Looks good otherwise.
**I apologize. I will make the correction immediately.**
This merge request was closed by zhengyong chen.