ValveSoftware / halflife

Half-Life 1 engine based games
Other
3.71k stars 626 forks source link

[Condition Zero] Material system leaks memory when parsing configuration files #3217

Open SamVanheer opened 2 years ago

SamVanheer commented 2 years ago

When the material system parses configuration data from material files it frees the file's contents incorrectly. The function MAT_SetDefaults loads the file, parses the data and then passes a null pointer to gEngfuncs.COM_FreeFile.

The cause is the same as #1729: the original pointer is modified during parsing, parsing doesn't end until the pointer becomes null at which point it is passed to gEngfuncs.COM_FreeFile.

The function also doesn't free the memory if the file syntax is incorrect, as it will return from the function without calling FreeFile.

This affects both Condition Zero and Deleted Scenes.

SamVanheer commented 2 years ago

The LoadLevelMaterials function also frees a file buffer incorrectly due to the same parsing-related mistake.