From f124259e591fbf76fad734906bfb4288edfe9678 Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Fri, 12 Nov 2021 17:25:24 -0600
Subject: [PATCH] testautomation: fix use-after-free when restoring hint value
---
test/testautomation_hints.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/test/testautomation_hints.c b/test/testautomation_hints.c
index b8d9ac1f45..2c491100d9 100644
--- a/test/testautomation_hints.c
+++ b/test/testautomation_hints.c
@@ -113,6 +113,9 @@ hints_setHint(void *arg)
/* Capture current value */
originalValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s)", (char*)_HintsEnum[i]);
+
+ /* Copy the original value, since it will be freed when we set it again */
+ originalValue = originalValue ? SDL_strdup(originalValue) : NULL;
/* Set value (twice) */
for (j=1; j<=2; j++) {
@@ -138,6 +141,7 @@ hints_setHint(void *arg)
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
+ SDL_free(originalValue);
}
SDL_free(value);