Skip to content

Commit 786f5a1

Browse files
author
Michael Martin
committed
[win32k]
- When message are sent without waiting a reply (non-queued messages) the message queues are referenced and dereferenced in the call. Message removal and cleanup functions for queues expected a reference on the queue. Add checks to determine if the message is a non-queued message and if so release memory for those that had pointers and more importantly skip dereferencing the queues. Possibly fixes random crashes and memory leaks. svn path=/trunk/; revision=47142
1 parent 330de81 commit 786f5a1

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

reactos/subsystems/win32/win32k/ntuser/msgqueue.c

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ MsqRemoveWindowMessagesFromQueue(PVOID pWindow)
10721072
{
10731073
DPRINT("Notify the sender and remove a message from the queue that had not been dispatched\n");
10741074

1075-
RemoveEntryList(&SentMessage->ListEntry);
1075+
RemoveEntryList(&SentMessage->ListEntry);
10761076

10771077
/* remove the message from the dispatching list */
10781078
if(SentMessage->DispatchingListEntry.Flink != NULL)
@@ -1086,9 +1086,19 @@ MsqRemoveWindowMessagesFromQueue(PVOID pWindow)
10861086
KeSetEvent(SentMessage->CompletionEvent, IO_NO_INCREMENT, FALSE);
10871087
}
10881088

1089-
/* dereference our and the sender's message queue */
1090-
IntDereferenceMessageQueue(MessageQueue);
1091-
IntDereferenceMessageQueue(SentMessage->SenderQueue);
1089+
if (SentMessage->HasPackedLParam == TRUE)
1090+
{
1091+
if (SentMessage->Msg.lParam)
1092+
ExFreePool((PVOID)SentMessage->Msg.lParam);
1093+
}
1094+
1095+
/* Only if it is not a no wait message */
1096+
if (!(SentMessage->HookMessage & MSQ_SENTNOWAIT))
1097+
{
1098+
/* dereference our and the sender's message queue */
1099+
IntDereferenceMessageQueue(MessageQueue);
1100+
IntDereferenceMessageQueue(SentMessage->SenderQueue);
1101+
}
10921102

10931103
/* free the message */
10941104
ExFreePool(SentMessage);
@@ -1509,9 +1519,19 @@ MsqCleanupMessageQueue(PUSER_MESSAGE_QUEUE MessageQueue)
15091519
KeSetEvent(CurrentSentMessage->CompletionEvent, IO_NO_INCREMENT, FALSE);
15101520
}
15111521

1512-
/* dereference our and the sender's message queue */
1513-
IntDereferenceMessageQueue(MessageQueue);
1514-
IntDereferenceMessageQueue(CurrentSentMessage->SenderQueue);
1522+
if (CurrentSentMessage->HasPackedLParam == TRUE)
1523+
{
1524+
if (CurrentSentMessage->Msg.lParam)
1525+
ExFreePool((PVOID)CurrentSentMessage->Msg.lParam);
1526+
}
1527+
1528+
/* Only if it is not a no wait message */
1529+
if (!(CurrentSentMessage->HookMessage & MSQ_SENTNOWAIT))
1530+
{
1531+
/* dereference our and the sender's message queue */
1532+
IntDereferenceMessageQueue(MessageQueue);
1533+
IntDereferenceMessageQueue(CurrentSentMessage->SenderQueue);
1534+
}
15151535

15161536
/* free the message */
15171537
ExFreePool(CurrentSentMessage);
@@ -1547,10 +1567,19 @@ MsqCleanupMessageQueue(PUSER_MESSAGE_QUEUE MessageQueue)
15471567
KeSetEvent(CurrentSentMessage->CompletionEvent, IO_NO_INCREMENT, FALSE);
15481568
}
15491569

1550-
/* dereference our and the sender's message queue */
1551-
IntDereferenceMessageQueue(MessageQueue);
1552-
IntDereferenceMessageQueue(CurrentSentMessage->SenderQueue);
1570+
if (CurrentSentMessage->HasPackedLParam == TRUE)
1571+
{
1572+
if (CurrentSentMessage->Msg.lParam)
1573+
ExFreePool((PVOID)CurrentSentMessage->Msg.lParam);
1574+
}
15531575

1576+
/* Only if it is not a no wait message */
1577+
if (!(CurrentSentMessage->HookMessage & MSQ_SENTNOWAIT))
1578+
{
1579+
/* dereference our and the sender's message queue */
1580+
IntDereferenceMessageQueue(MessageQueue);
1581+
IntDereferenceMessageQueue(CurrentSentMessage->SenderQueue);
1582+
}
15541583
/* free the message */
15551584
ExFreePool(CurrentSentMessage);
15561585
}

0 commit comments

Comments
 (0)