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:
Haroldo Santos authored and Carlos R. Mafra committed 2026-10-21 12:20:34 +01:00
1 parent 56ec56136f
commit c0104d56bf
1 file changed
+1
+1
View File
@@ -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);