From 5b130aae74d43139e5292104a085c19fc1a24b1e Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Fri, 17 Mar 2023 19:53:47 +0200 Subject: [PATCH] Fix potentially invalid pointer being passed to free --- Quake/host_cmd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Quake/host_cmd.c b/Quake/host_cmd.c index b6a75e7a0..188dabd0f 100644 --- a/Quake/host_cmd.c +++ b/Quake/host_cmd.c @@ -1087,15 +1087,16 @@ static void Modlist_Add (const char *name) for (i = com_numbasedirs - 1; i >= 0; i--) { char path[MAX_OSPATH]; - char *description, *end; + char *buf, *description, *end; if (q_snprintf (path, sizeof (path), "%s/%s/descript.ion", com_basedirs[i], name) >= sizeof (path)) continue; - description = (char *) COM_LoadMallocFile_TextMode_OSPath (path, NULL); - if (!description) + buf = (char *) COM_LoadMallocFile_TextMode_OSPath (path, NULL); + if (!buf) continue; + description = buf; while (q_isspace (*description)) ++description; end = strchr (description, '\n'); @@ -1103,8 +1104,8 @@ static void Modlist_Add (const char *name) *end = '\0'; if (*description) info->full_name = strdup (description); - free (description); - + free (buf); + if (info->full_name) break; }