mirror of
https://github.com/gryf/wmaker.git
synced 2026-11-20 22:26:54 +01:00
wrlib: do not use the image cache when its allocation fails
init_cache() allocates RImageCache with malloc() for RImageCacheSize entries. When the allocation fails it prints a warning and returns, but leaves RImageCacheSize at its positive value. RLoadImage() decides whether to use the cache by testing RImageCacheSize > 0, so after such a failure every image load walks RImageCache[i] through a NULL pointer and crashes. RReleaseCache() likewise loops over the missing entries. Reset RImageCacheSize to 0 when the allocation fails, so images are simply loaded without caching, as already happens when the cache is disabled by configuration. Signed-off-by: Haroldo Santos <haroldo.santos@gmail.com>
This commit is contained in:
1 parent
56ec56136f
commit
c0104d56bf
1 file changed
+1
@@ -130,6 +130,7 @@ static void init_cache(void)
|
||||
RImageCache = malloc(sizeof(RCachedImage) * RImageCacheSize);
|
||||
if (RImageCache == NULL) {
|
||||
fprintf(stderr, _("wrlib: out of memory for image cache\n"));
|
||||
RImageCacheSize = 0;
|
||||
return;
|
||||
}
|
||||
memset(RImageCache, 0, sizeof(RCachedImage) * RImageCacheSize);
|
||||
|
||||
Reference in new issue
Block a user