refactor: delegate strdup'd command string buffer freeing to compileShader and remove a redundant free.

This commit is contained in:
dkeruza-neo
2026-02-17 22:51:30 -05:00
parent c47a4a6889
commit 973cfb7058
2 changed files with 12 additions and 7 deletions
+7
View File
@@ -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).
+5 -7
View File
@@ -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;
}