Fix shaderc leaks (#1313)

* Fix fcpp memory leaks

* Fix glsl_optimizer leaks
This commit is contained in:
Lectem 2018-01-13 19:08:03 +01:00 committed by Branimir Karadžić
parent 9be9848f9b
commit 7960b42c90
6 changed files with 42 additions and 5 deletions

11
3rdparty/fcpp/cpp1.c vendored
View File

@ -42,6 +42,7 @@ int fppPreProcess(struct fppTag *tags)
{ {
size_t i=0; size_t i=0;
ReturnCode ret; /* cpp return code */ ReturnCode ret; /* cpp return code */
int retVal; /* fppPreProcess return code */
struct Global *global; struct Global *global;
global=(struct Global *)malloc(sizeof(struct Global)); global=(struct Global *)malloc(sizeof(struct Global));
@ -144,10 +145,16 @@ int fppPreProcess(struct fppTag *tags)
} }
fflush(stdout); fflush(stdout);
// BK - fclose(stdout); // BK - fclose(stdout);
delalldefines(global);
retVal = IO_NORMAL;
if (global->errors > 0 && !global->eflag) if (global->errors > 0 && !global->eflag)
return(IO_ERROR); retVal = IO_ERROR;
return(IO_NORMAL); /* No errors or -E option set */ free(global->tokenbuf);
free(global->functionname);
free(global->spacebuf);
free(global);
return retVal; /* No errors or -E option set */
} }
INLINE FILE_LOCAL INLINE FILE_LOCAL

View File

@ -363,7 +363,7 @@ ReturnCode initdefines(struct Global *global)
return(FPP_OK); return(FPP_OK);
} }
void deldefines(struct Global *global) void delbuiltindefines(struct Global *global)
{ {
/* /*
* Delete the built-in #define's. * Delete the built-in #define's.

25
3rdparty/fcpp/cpp6.c vendored
View File

@ -619,12 +619,35 @@ DEFBUF *defendel(struct Global *global,
} }
void delalldefines(struct Global *global)
{
/*
* Delete all the defines in the tables and free memory
*/
DEFBUF *dp;
DEFBUF *prevp;
int i;
for (i = 0; i < SBSIZE; ++i)
{
prevp = global->symtab[i];
while ((dp = prevp) != (DEFBUF *)NULL) {
prevp = dp->link;
free(dp->repl); /* Free the replacement */
free((char *)dp); /* Free the symbol */
}
global->symtab[i] = NULL;
}
}
void outdefines(struct Global *global) void outdefines(struct Global *global)
{ {
DEFBUF *dp; DEFBUF *dp;
DEFBUF **syp; DEFBUF **syp;
deldefines(global); /* Delete built-in #defines */ delbuiltindefines(global); /* Delete built-in #defines */
for (syp = global->symtab; syp < &global->symtab[SBSIZE]; syp++) { for (syp = global->symtab; syp < &global->symtab[SBSIZE]; syp++) {
if ((dp = *syp) != (DEFBUF *) NULL) { if ((dp = *syp) != (DEFBUF *) NULL) {
do { do {

View File

@ -407,7 +407,8 @@ void dumpadef(char *, register DEFBUF *);
#endif #endif
ReturnCode openfile(struct Global *,char *); ReturnCode openfile(struct Global *,char *);
int cget(struct Global *); int cget(struct Global *);
void deldefines(struct Global *); void delbuiltindefines(struct Global *);
void delalldefines(struct Global *);
char *Getmem(struct Global *, int); char *Getmem(struct Global *, int);
ReturnCode openinclude(struct Global *, char *, int); ReturnCode openinclude(struct Global *, char *, int);
ReturnCode expstuff(struct Global *, char *, char *); ReturnCode expstuff(struct Global *, char *, char *);

View File

@ -170,6 +170,10 @@ struct glslopt_shader
{ {
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) for (unsigned i = 0; i < MESA_SHADER_STAGES; i++)
ralloc_free(whole_program->_LinkedShaders[i]); ralloc_free(whole_program->_LinkedShaders[i]);
for(GLuint i =0;i< whole_program->NumShaders;i++)
ralloc_free(whole_program->Shaders[i]);
ralloc_free(whole_program->Shaders);
ralloc_free(whole_program->InfoLog);
ralloc_free(whole_program); ralloc_free(whole_program);
ralloc_free(rawOutput); ralloc_free(rawOutput);
ralloc_free(optimizedOutput); ralloc_free(optimizedOutput);

View File

@ -62,6 +62,7 @@ namespace bgfx { namespace glsl
printCode(_code.c_str(), line, start, end, column); printCode(_code.c_str(), line, start, end, column);
fprintf(stderr, "Error: %s\n", log); fprintf(stderr, "Error: %s\n", log);
glslopt_shader_delete(shader);
glslopt_cleanup(ctx); glslopt_cleanup(ctx);
return false; return false;
} }
@ -298,6 +299,7 @@ namespace bgfx { namespace glsl
writeFile(disasmfp.c_str(), optimizedShader, shaderSize); writeFile(disasmfp.c_str(), optimizedShader, shaderSize);
} }
glslopt_shader_delete(shader);
glslopt_cleanup(ctx); glslopt_cleanup(ctx);
return true; return true;