SDL: Make sure we set datasize on error in SDL_LoadFile_RW()

From 2d94b4f4908c8173e1b234d545da383011745771 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 27 Jan 2024 12:19:27 -0800
Subject: [PATCH] Make sure we set datasize on error in SDL_LoadFile_RW()

---
 src/file/SDL_rwops.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c
index ab37994a956e..7c3c34d86861 100644
--- a/src/file/SDL_rwops.c
+++ b/src/file/SDL_rwops.c
@@ -625,14 +625,14 @@ void SDL_DestroyRW(SDL_RWops *context)
 void *SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc)
 {
     const int FILE_CHUNK_SIZE = 1024;
-    Sint64 size, size_total;
+    Sint64 size, size_total = 0;
     size_t size_read;
     char *data = NULL, *newdata;
     SDL_bool loading_chunks = SDL_FALSE;
 
     if (!src) {
         SDL_InvalidParamError("src");
-        return NULL;
+        goto done;
     }
 
     size = SDL_RWsize(src);
@@ -677,12 +677,12 @@ void *SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc)
         break;
     }
 
-    if (datasize) {
-        *datasize = (size_t)size_total;
-    }
     data[size_total] = '\0';
 
 done:
+    if (datasize) {
+        *datasize = (size_t)size_total;
+    }
     if (freesrc && src) {
         SDL_RWclose(src);
     }