Fixed missing checks for queue functions

This commit is contained in:
Armin Novak 2021-09-07 13:42:07 +02:00 committed by akallabeth
parent 6c859b4579
commit 4daa09c3e5
2 changed files with 11 additions and 6 deletions

View File

@ -268,7 +268,8 @@ void MessageQueue_Free(wMessageQueue* queue)
if (!queue) if (!queue)
return; return;
MessageQueue_Clear(queue); if (queue->event)
MessageQueue_Clear(queue);
CloseHandle(queue->event); CloseHandle(queue->event);
DeleteCriticalSection(&queue->lock); DeleteCriticalSection(&queue->lock);

View File

@ -40,6 +40,7 @@ struct _wQueue
HANDLE event; HANDLE event;
wObject object; wObject object;
BOOL haveLock;
}; };
/** /**
@ -283,6 +284,9 @@ wQueue* Queue_New(BOOL synchronized, SSIZE_T capacity, SSIZE_T growthFactor)
if (capacity <= 0) if (capacity <= 0)
capacity = 32; capacity = 32;
if (!InitializeCriticalSectionAndSpinCount(&queue->lock, 4000))
goto fail;
queue->haveLock = TRUE;
if (!Queue_EnsureCapacity(queue, (size_t)capacity)) if (!Queue_EnsureCapacity(queue, (size_t)capacity))
goto fail; goto fail;
@ -291,9 +295,6 @@ wQueue* Queue_New(BOOL synchronized, SSIZE_T capacity, SSIZE_T growthFactor)
if (!queue->event) if (!queue->event)
goto fail; goto fail;
if (!InitializeCriticalSectionAndSpinCount(&queue->lock, 4000))
goto fail;
obj = Queue_Object(queue); obj = Queue_Object(queue);
obj->fnObjectEquals = default_queue_equals; obj->fnObjectEquals = default_queue_equals;
@ -308,9 +309,12 @@ void Queue_Free(wQueue* queue)
if (!queue) if (!queue)
return; return;
Queue_Clear(queue); if (queue->haveLock)
{
Queue_Clear(queue);
DeleteCriticalSection(&queue->lock);
}
CloseHandle(queue->event); CloseHandle(queue->event);
DeleteCriticalSection(&queue->lock);
free(queue->array); free(queue->array);
free(queue); free(queue);
} }