From c0104d56bfdf762e649fb037c77be4eb0f18a6a0 Mon Sep 17 00:00:00 2001 From: Haroldo Santos Date: Sat, 10 Oct 2026 17:31:44 -0400 Subject: [PATCH] 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 --- wrlib/load.c | 1 + 1 file changed, 1 insertion(+) diff --git a/wrlib/load.c b/wrlib/load.c index a1399756..5ab0f67a 100644 --- a/wrlib/load.c +++ b/wrlib/load.c @@ -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);