diff options
author | Xiang, Haihao <haihao.xiang@intel.com> | 2013-03-07 10:04:10 +0800 |
---|---|---|
committer | Xiang, Haihao <haihao.xiang@intel.com> | 2013-03-15 15:45:28 +0800 |
commit | 5aaf36cb48106bd2b7bb042019c79aefbcfd74f3 (patch) | |
tree | 6ea029a0360f2b8bb47f8ea31562faed81aa6238 | |
parent | 9178a2893eb45724fdcdbc7adfe11aa7dbde39cf (diff) | |
download | vaapi-intel-driver-5aaf36cb48106bd2b7bb042019c79aefbcfd74f3.tar.gz vaapi-intel-driver-5aaf36cb48106bd2b7bb042019c79aefbcfd74f3.tar.bz2 vaapi-intel-driver-5aaf36cb48106bd2b7bb042019c79aefbcfd74f3.zip |
Fix object_heap_init() & object_heap_destroy()
Don't allocate resources if failed to initialize a heap
Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
-rw-r--r-- | src/object_heap.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/src/object_heap.c b/src/object_heap.c index 1a92579..cc6f60b 100644 --- a/src/object_heap.c +++ b/src/object_heap.c @@ -89,10 +89,21 @@ int object_heap_init( object_heap_p heap, int object_size, int id_offset) heap->heap_size = 0; heap->heap_increment = 16; heap->next_free = LAST_FREE; - _i965InitMutex(&heap->mutex); heap->num_buckets = 0; heap->bucket = NULL; - return object_heap_expand(heap); + + if (object_heap_expand(heap) == 0) { + ASSERT(heap->heap_size); + _i965InitMutex(&heap->mutex); + return 0; + } else { + ASSERT(!heap->heap_size); + ASSERT(!heap->bucket || !heap->bucket[0]); + + free(heap->bucket); + + return -1; + } } /* @@ -224,23 +235,26 @@ void object_heap_destroy( object_heap_p heap ) int i; int bucket_index, obj_index; - _i965DestroyMutex(&heap->mutex); + if (heap->heap_size) { + _i965DestroyMutex(&heap->mutex); - /* Check if heap is empty */ - for (i = 0; i < heap->heap_size; i++) - { - /* Check if object is not still allocated */ - bucket_index = i / heap->heap_increment; - obj_index = i % heap->heap_increment; - obj = (object_base_p) (heap->bucket[bucket_index] + obj_index * heap->object_size); - ASSERT( obj->next_free != ALLOCATED ); - } + /* Check if heap is empty */ + for (i = 0; i < heap->heap_size; i++) + { + /* Check if object is not still allocated */ + bucket_index = i / heap->heap_increment; + obj_index = i % heap->heap_increment; + obj = (object_base_p) (heap->bucket[bucket_index] + obj_index * heap->object_size); + ASSERT( obj->next_free != ALLOCATED ); + } + + for (i = 0; i < heap->heap_size / heap->heap_increment; i++) { + free(heap->bucket[i]); + } - for (i = 0; i < heap->heap_size / heap->heap_increment; i++) { - free(heap->bucket[i]); + free(heap->bucket); } - free(heap->bucket); heap->bucket = NULL; heap->heap_size = 0; heap->next_free = LAST_FREE; |