client: Fix memory leaks

This commit is contained in:
Denis Pauk 2024-08-27 01:19:26 +03:00
parent 33ebf6c193
commit b3efe338c1
3 changed files with 45 additions and 9 deletions

View file

@ -5712,11 +5712,19 @@ HasSkinsInDir(const char *dirname, int *num)
for (j = 0; j < num_png; j ++) for (j = 0; j < num_png; j ++)
{ {
if (list_png[j] && !strchr(list_png[j] + dirname_size, '/')) if (list_png[j])
{
if (!strchr(list_png[j] + dirname_size, '/'))
{ {
*curr = list_png[j]; *curr = list_png[j];
curr++; curr++;
} }
else
{
/* unused in final response */
free(list_png[j]);
}
}
} }
free(list_png); free(list_png);
@ -5728,11 +5736,19 @@ HasSkinsInDir(const char *dirname, int *num)
for (j = 0; j < num_pcx; j ++) for (j = 0; j < num_pcx; j ++)
{ {
if (list_pcx[j] && !strchr(list_pcx[j] + dirname_size, '/')) if (list_pcx[j])
{
if (!strchr(list_pcx[j] + dirname_size, '/'))
{ {
*curr = list_pcx[j]; *curr = list_pcx[j];
curr++; curr++;
} }
else
{
/* unused in final response */
free(list_pcx[j]);
}
}
} }
free(list_pcx); free(list_pcx);
@ -5744,11 +5760,19 @@ HasSkinsInDir(const char *dirname, int *num)
for (j = 0; j < num_m8; j ++) for (j = 0; j < num_m8; j ++)
{ {
if (list_m8[j] && !strchr(list_m8[j] + dirname_size, '/')) if (list_m8[j])
{
if (!strchr(list_m8[j] + dirname_size, '/'))
{ {
*curr = list_m8[j]; *curr = list_m8[j];
curr++; curr++;
} }
else
{
/* unused in final response */
free(list_m8[j]);
}
}
} }
free(list_m8); free(list_m8);

View file

@ -880,6 +880,12 @@ FS_LoadFile(const char *path, void **buffer)
if (size <= 0) if (size <= 0)
{ {
if (size == 0)
{
/* empty file, close before exit*/
FS_FCloseFile(f);
}
if (buffer) if (buffer)
{ {
*buffer = NULL; *buffer = NULL;

View file

@ -175,6 +175,12 @@ Mod_LoadFileMD5Merge(const char *namewe, void **buffer)
i, md5skinname); i, md5skinname);
} }
} }
/* clean up original buffer */
if (skins)
{
free(skins);
}
} }
/* prepare final file */ /* prepare final file */