From 973cfb7058daa8109685631705742a4086295f29 Mon Sep 17 00:00:00 2001 From: dkeruza-neo Date: Tue, 17 Feb 2026 22:51:30 -0500 Subject: [PATCH] refactor: delegate `strdup`'d command string buffer freeing to `compileShader` and remove a redundant free. --- docs/changelog | 7 +++++++ src/lindbergh/shaderPatches.c | 12 +++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/changelog b/docs/changelog index af9c7a6..f7bbdb2 100644 --- a/docs/changelog +++ b/docs/changelog @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. + +## [2.1.3] +### Added + - MJ4 Rev. A, MJ4 Rev. F and MJ4 Evolution Rev. B support. +### Fixed + - Fixed a bug in the shader patching code that prevented the loader to compile shaders for non nVidia GPUs. + ## [2.1.2] ### Added - Virtual Card file support for ID4 and ID5 (read the documentation). diff --git a/src/lindbergh/shaderPatches.c b/src/lindbergh/shaderPatches.c index 16843f1..25ce447 100644 --- a/src/lindbergh/shaderPatches.c +++ b/src/lindbergh/shaderPatches.c @@ -976,10 +976,10 @@ void glBindTexture(GLenum target, GLuint texture) } } -int parseCgcArgs(const char *input, const char ***compilerArgs, const char **outputFileName) +int parseCgcArgs(const char *input, const char ***compilerArgs, const char **outputFileName, char **bufferToFree) { char *inputCopy = strdup(input); - char *toFree = inputCopy; + *bufferToFree = inputCopy; char *token = strtok(inputCopy, " "); char **args = malloc(256 * sizeof(char *)); int count = 0; @@ -1014,7 +1014,6 @@ int parseCgcArgs(const char *input, const char ***compilerArgs, const char **out } (*compilerArgs)[argIndex] = NULL; free(args); - free(toFree); if (strcmp(profile, "vp40") == 0) { return 6150; @@ -1215,9 +1214,9 @@ int compileWithCGC(char *command) { const char **compilerArgs = NULL; const char *outputFileName = NULL; + char *argsBuffer = NULL; - int profile = parseCgcArgs(command, &compilerArgs, &outputFileName); - + int profile = parseCgcArgs(command, &compilerArgs, &outputFileName, &argsBuffer); size_t *ctx = _cgCreateContext(); char *program = NULL; @@ -1248,10 +1247,9 @@ int compileWithCGC(char *command) fprintf(outputFile, "%s", compiledSource); fclose(outputFile); - + free(argsBuffer); _cgDestroyProgram(program); _cgDestroyContext(ctx); - free((void *)*compilerArgs); return 0; }