From ea152532204a4f5d9d4ccde173f2532a80493ad8 Mon Sep 17 00:00:00 2001
From: pionere <[EMAIL REDACTED]>
Date: Wed, 18 May 2022 17:23:26 +0200
Subject: [PATCH] fix GetNearbyFilename - fix memory leak due to variable
'base' - fix usage of uninitialized variable (path)
---
test/testutils.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/test/testutils.c b/test/testutils.c
index 3bb2b9c0e87..fa21fe2a87b 100644
--- a/test/testutils.c
+++ b/test/testutils.c
@@ -35,15 +35,18 @@ GetNearbyFilename(const char *file)
path = SDL_malloc(len);
if (path == NULL) {
+ SDL_free(base);
SDL_OutOfMemory();
return NULL;
}
SDL_snprintf(path, len, "%s%s%s", base, pathsep, file);
- }
-
- if (base) {
SDL_free(base);
+ } else {
+ path = SDL_strdup(file);
+ if (path == NULL) {
+ SDL_OutOfMemory();
+ }
}
return path;