Fixes in case of OOM

This commit is contained in:
Hardening 2014-04-09 15:26:43 +02:00
parent aa466a85e0
commit 36b4f20ff8
2 changed files with 37 additions and 35 deletions

View File

@ -378,24 +378,24 @@ wArrayList* ArrayList_New(BOOL synchronized)
{
wArrayList* arrayList = NULL;
arrayList = (wArrayList*) malloc(sizeof(wArrayList));
arrayList = (wArrayList *)calloc(1, sizeof(wArrayList));
if (!arrayList)
return NULL;
if (arrayList)
{
arrayList->synchronized = synchronized;
arrayList->synchronized = synchronized;
arrayList->capacity = 32;
arrayList->growthFactor = 2;
arrayList->size = 0;
arrayList->capacity = 32;
arrayList->growthFactor = 2;
arrayList->array = (void**) malloc(sizeof(void*) * arrayList->capacity);
InitializeCriticalSectionAndSpinCount(&arrayList->lock, 4000);
ZeroMemory(&arrayList->object, sizeof(wObject));
}
arrayList->array = (void **)malloc(arrayList->capacity * sizeof(void *));
if (!arrayList->array)
goto out_free;
InitializeCriticalSectionAndSpinCount(&arrayList->lock, 4000);
return arrayList;
out_free:
free(arrayList);
return NULL;
}
void ArrayList_Free(wArrayList* arrayList)

View File

@ -221,35 +221,37 @@ wQueue* Queue_New(BOOL synchronized, int capacity, int growthFactor)
{
wQueue* queue = NULL;
queue = (wQueue*) malloc(sizeof(wQueue));
queue = (wQueue *)calloc(1, sizeof(wQueue));
if (!queue)
return NULL;
if (queue)
{
queue->head = 0;
queue->tail = 0;
queue->size = 0;
queue->capacity = 32;
queue->growthFactor = 2;
queue->capacity = 32;
queue->growthFactor = 2;
queue->synchronized = synchronized;
queue->synchronized = synchronized;
if (capacity > 0)
queue->capacity = capacity;
if (capacity > 0)
queue->capacity = capacity;
if (growthFactor > 0)
queue->growthFactor = growthFactor;
if (growthFactor > 0)
queue->growthFactor = growthFactor;
queue->array = (void **)calloc(queue->capacity, sizeof(void *));
if (!queue->array)
goto out_free;
queue->array = (void**) malloc(sizeof(void*) * queue->capacity);
ZeroMemory(queue->array, sizeof(void*) * queue->capacity);
InitializeCriticalSectionAndSpinCount(&queue->lock, 4000);
queue->event = CreateEvent(NULL, TRUE, FALSE, NULL);
ZeroMemory(&queue->object, sizeof(wObject));
}
InitializeCriticalSectionAndSpinCount(&queue->lock, 4000);
queue->event = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!queue->event)
goto out_free_array;
return queue;
out_free_array:
free(queue->array);
out_free:
free(queue);
return NULL;
}
void Queue_Free(wQueue* queue)