From 11300cd37fc0038f3004b0da5748091f5f763738 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 9 Nov 2014 10:41:54 +0100 Subject: Check more mallocs This is just a start and gets most easy ones. --- libass/ass_cache.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libass/ass_cache.c') diff --git a/libass/ass_cache.c b/libass/ass_cache.c index e5e77fc..a0a00b3 100644 --- a/libass/ass_cache.c +++ b/libass/ass_cache.c @@ -237,6 +237,8 @@ Cache *ass_cache_create(HashFunction hash_func, HashCompare compare_func, size_t key_size, size_t value_size) { Cache *cache = calloc(1, sizeof(*cache)); + if (!cache) + return NULL; cache->buckets = 0xFFFF; cache->hash_func = hash_simple; cache->compare_func = compare_simple; @@ -251,6 +253,10 @@ Cache *ass_cache_create(HashFunction hash_func, HashCompare compare_func, cache->key_size = key_size; cache->value_size = value_size; cache->map = calloc(cache->buckets, sizeof(CacheItem *)); + if (!cache->map) { + free(cache); + return NULL; + } return cache; } @@ -261,8 +267,16 @@ void *ass_cache_put(Cache *cache, void *key, void *value) CacheItem **bucketptr = &cache->map[bucket]; CacheItem *item = calloc(1, sizeof(CacheItem)); + if (!item) + return NULL; item->key = malloc(cache->key_size); item->value = malloc(cache->value_size); + if (!item->key || !item->value) { + free(item->key); + free(item->value); + free(item); + return NULL; + } memcpy(item->key, key, cache->key_size); memcpy(item->value, value, cache->value_size); -- cgit v1.2.3