SDL_image: stb_image.h: update mainstream issue/1838 patch from mainstream PR/1839

From 13ec6e9be1d69d2a989ec1fc4f09e8743ef3932d Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 5 Dec 2025 03:30:20 +0300
Subject: [PATCH] stb_image.h: update mainstream issue/1838 patch from
 mainstream PR/1839

patch authored by @NBickford-NV.
---
 src/stb_image.h | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/stb_image.h b/src/stb_image.h
index 03c22e02..5b393bdc 100644
--- a/src/stb_image.h
+++ b/src/stb_image.h
@@ -7185,15 +7185,19 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y,
             stride = g.w * g.h * 4;
 
             if (out) {
-               out = (stbi_uc*) STBI_REALLOC_SIZED( out, out_size, layers * stride );
-               if (!out)
+               void *tmp = (stbi_uc*) STBI_REALLOC_SIZED( out, out_size, layers * stride );
+               if (!tmp)
                   return stbi__load_gif_main_outofmem(&g, out, delays);
-               out_size = layers * stride;
+               else {
+                   out = (stbi_uc*) tmp;
+                   out_size = layers * stride;
+               }
 
                if (delays) {
-                  *delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers );
-                  if (!*delays)
+                  int *new_delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers );
+                  if (!new_delays)
                      return stbi__load_gif_main_outofmem(&g, out, delays);
+                  *delays = new_delays;
                   delays_size = layers * sizeof(int);
                }
             } else {