summaryrefslogtreecommitdiffstats
path: root/libass/ass_cache.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-11-09 10:41:54 +0100
committerwm4 <wm4@nowhere>2014-11-09 10:41:54 +0100
commit11300cd37fc0038f3004b0da5748091f5f763738 (patch)
tree243fa115af89216ee2a4463edcef440c488f7448 /libass/ass_cache.c
parentdc054a1fdb1e9145e905612f296bbafd5ba7b530 (diff)
downloadlibass-11300cd37fc0038f3004b0da5748091f5f763738.tar.bz2
libass-11300cd37fc0038f3004b0da5748091f5f763738.tar.xz
Check more mallocs
This is just a start and gets most easy ones.
Diffstat (limited to 'libass/ass_cache.c')
-rw-r--r--libass/ass_cache.c14
1 files changed, 14 insertions, 0 deletions
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);