Commit 34319496 authored by Yuxuan Shui's avatar Yuxuan Shui Committed by Alexandre Julliard

rtworkq: Fix leak of thread pool work items.

parent 20f88c83
...@@ -118,6 +118,13 @@ enum system_queue_index ...@@ -118,6 +118,13 @@ enum system_queue_index
SYS_QUEUE_COUNT, SYS_QUEUE_COUNT,
}; };
enum work_item_type
{
WORK_ITEM_WORK,
WORK_ITEM_TIMER,
WORK_ITEM_WAIT,
};
struct work_item struct work_item
{ {
IUnknown IUnknown_iface; IUnknown IUnknown_iface;
...@@ -129,10 +136,11 @@ struct work_item ...@@ -129,10 +136,11 @@ struct work_item
RTWQWORKITEM_KEY key; RTWQWORKITEM_KEY key;
LONG priority; LONG priority;
DWORD flags; DWORD flags;
TP_WORK *work_object;
PTP_SIMPLE_CALLBACK finalization_callback; PTP_SIMPLE_CALLBACK finalization_callback;
enum work_item_type type;
union union
{ {
TP_WORK *work_object;
TP_WAIT *wait_object; TP_WAIT *wait_object;
TP_TIMER *timer_object; TP_TIMER *timer_object;
} u; } u;
...@@ -387,8 +395,9 @@ static void pool_queue_submit(struct queue *queue, struct work_item *item) ...@@ -387,8 +395,9 @@ static void pool_queue_submit(struct queue *queue, struct work_item *item)
we need finalization callback. */ we need finalization callback. */
if (item->finalization_callback) if (item->finalization_callback)
IUnknown_AddRef(&item->IUnknown_iface); IUnknown_AddRef(&item->IUnknown_iface);
item->work_object = CreateThreadpoolWork(standard_queue_worker, item, (TP_CALLBACK_ENVIRON *)&env); item->u.work_object = CreateThreadpoolWork(standard_queue_worker, item, (TP_CALLBACK_ENVIRON *)&env);
SubmitThreadpoolWork(item->work_object); item->type = WORK_ITEM_WORK;
SubmitThreadpoolWork(item->u.work_object);
TRACE("dispatched %p.\n", item->result); TRACE("dispatched %p.\n", item->result);
} }
...@@ -549,8 +558,18 @@ static ULONG WINAPI work_item_Release(IUnknown *iface) ...@@ -549,8 +558,18 @@ static ULONG WINAPI work_item_Release(IUnknown *iface)
if (!refcount) if (!refcount)
{ {
if (item->work_object) switch (item->type)
CloseThreadpoolWork(item->work_object); {
case WORK_ITEM_WORK:
if (item->u.work_object) CloseThreadpoolWork(item->u.work_object);
break;
case WORK_ITEM_WAIT:
if (item->u.wait_object) CloseThreadpoolWait(item->u.wait_object);
break;
case WORK_ITEM_TIMER:
if (item->u.timer_object) CloseThreadpoolTimer(item->u.timer_object);
break;
}
if (item->reply_result) if (item->reply_result)
IRtwqAsyncResult_Release(item->reply_result); IRtwqAsyncResult_Release(item->reply_result);
IRtwqAsyncResult_Release(item->result); IRtwqAsyncResult_Release(item->result);
...@@ -814,6 +833,7 @@ static HRESULT queue_submit_wait(struct queue *queue, HANDLE event, LONG priorit ...@@ -814,6 +833,7 @@ static HRESULT queue_submit_wait(struct queue *queue, HANDLE event, LONG priorit
item->u.wait_object = CreateThreadpoolWait(callback, item, item->u.wait_object = CreateThreadpoolWait(callback, item,
(TP_CALLBACK_ENVIRON *)&queue->envs[TP_CALLBACK_PRIORITY_NORMAL]); (TP_CALLBACK_ENVIRON *)&queue->envs[TP_CALLBACK_PRIORITY_NORMAL]);
item->type = WORK_ITEM_WAIT;
SetThreadpoolWait(item->u.wait_object, event, NULL); SetThreadpoolWait(item->u.wait_object, event, NULL);
TRACE("dispatched %p.\n", result); TRACE("dispatched %p.\n", result);
...@@ -848,6 +868,7 @@ static HRESULT queue_submit_timer(struct queue *queue, IRtwqAsyncResult *result, ...@@ -848,6 +868,7 @@ static HRESULT queue_submit_timer(struct queue *queue, IRtwqAsyncResult *result,
item->u.timer_object = CreateThreadpoolTimer(callback, item, item->u.timer_object = CreateThreadpoolTimer(callback, item,
(TP_CALLBACK_ENVIRON *)&queue->envs[TP_CALLBACK_PRIORITY_NORMAL]); (TP_CALLBACK_ENVIRON *)&queue->envs[TP_CALLBACK_PRIORITY_NORMAL]);
item->type = WORK_ITEM_TIMER;
SetThreadpoolTimer(item->u.timer_object, &filetime, period, 0); SetThreadpoolTimer(item->u.timer_object, &filetime, period, 0);
TRACE("dispatched %p.\n", result); TRACE("dispatched %p.\n", result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment