Merge pull request #718 from Spirrwell/master

Fix some leaks
This commit is contained in:
Yamagi 2021-06-19 08:48:54 +02:00 committed by GitHub
commit 21483dc1bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 106 additions and 24 deletions

View file

@ -1129,6 +1129,20 @@ Key_Init(void)
Cmd_AddCommand("bindlist", Key_Bindlist_f); Cmd_AddCommand("bindlist", Key_Bindlist_f);
} }
void
Key_Shutdown(void)
{
int i;
for (i = 0; i < K_LAST; ++i)
{
if (keybindings[i])
{
Z_Free(keybindings[i]);
keybindings[i] = NULL;
}
}
}
/* /*
* Called every frame for every detected keypress. * Called every frame for every detected keypress.
* ASCII input for the console, the menu and the * ASCII input for the console, the menu and the

View file

@ -310,6 +310,7 @@ extern qboolean chat_team;
void Char_Event(int key); void Char_Event(int key);
void Key_Event(int key, qboolean down, qboolean special); void Key_Event(int key, qboolean down, qboolean special);
void Key_Init(void); void Key_Init(void);
void Key_Shutdown(void);
void Key_WriteBindings(FILE *f); void Key_WriteBindings(FILE *f);
void Key_ReadConsoleHistory(); void Key_ReadConsoleHistory();
void Key_WriteConsoleHistory(); void Key_WriteConsoleHistory();

View file

@ -1514,6 +1514,10 @@ IN_Shutdown(void)
SDL_JoystickClose(joystick); SDL_JoystickClose(joystick);
joystick = NULL; joystick = NULL;
} }
const Uint32 subsystems = SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC;
if (SDL_WasInit(subsystems) == subsystems)
SDL_QuitSubSystem(subsystems);
} }
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */

View file

@ -440,7 +440,9 @@ GLimp_Shutdown(void)
{ {
ShutdownGraphics(); ShutdownGraphics();
if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_VIDEO) // SDL_INIT_VIDEO implies SDL_INIT_EVENTS
const Uint32 subsystems = SDL_INIT_VIDEO | SDL_INIT_EVENTS;
if (SDL_WasInit(SDL_INIT_EVERYTHING) == subsystems)
{ {
SDL_Quit(); SDL_Quit();
} }

View file

@ -1131,3 +1131,16 @@ Cmd_Init(void)
Cmd_AddCommand("wait", Cmd_Wait_f); Cmd_AddCommand("wait", Cmd_Wait_f);
} }
void
Cmd_Shutdown(void)
{
cmdalias_t *next;
while (cmd_alias != NULL)
{
next = cmd_alias->next;
Z_Free(cmd_alias->value);
Z_Free(cmd_alias);
cmd_alias = next;
}
}

View file

@ -229,6 +229,9 @@ Cvar_Get(char *var_name, char *var_value, int flags)
{ {
var->flags |= flags; var->flags |= flags;
if (var->default_string)
Z_Free(var->default_string);
if (!var_value) if (!var_value)
{ {
var->default_string = CopyString(""); var->default_string = CopyString("");
@ -874,6 +877,7 @@ Cvar_Fini(void)
cvar_t *c = var->next; cvar_t *c = var->next;
Z_Free(var->string); Z_Free(var->string);
Z_Free(var->name); Z_Free(var->name);
Z_Free(var->default_string);
Z_Free(var); Z_Free(var);
var = c; var = c;
} }

View file

@ -687,6 +687,52 @@ FS_FreeFile(void *buffer)
Z_Free(buffer); Z_Free(buffer);
} }
fsRawPath_t *FS_FreeRawPaths(fsRawPath_t *start, fsRawPath_t *end)
{
fsRawPath_t *cur = start;
fsRawPath_t *next;
while (cur != end)
{
next = cur->next;
Z_Free(cur);
cur = next;
}
return cur;
}
fsSearchPath_t *FS_FreeSearchPaths(fsSearchPath_t *start, fsSearchPath_t *end)
{
fsSearchPath_t *cur = start;
fsSearchPath_t *next;
while (cur != end)
{
if (cur->pack)
{
if (cur->pack->pak)
{
fclose(cur->pack->pak);
}
if (cur->pack->pk3)
{
unzClose(cur->pack->pk3);
}
Z_Free(cur->pack->files);
Z_Free(cur->pack);
}
next = cur->next;
Z_Free(cur);
cur = next;
}
return cur;
}
/* /*
* Takes an explicit (not game tree related) path to a pak file. * Takes an explicit (not game tree related) path to a pak file.
* *
@ -1680,7 +1726,6 @@ FS_BuildGameSpecificSearchPath(char *dir)
char path[MAX_OSPATH]; char path[MAX_OSPATH];
int i; int i;
fsRawPath_t *search; fsRawPath_t *search;
fsSearchPath_t *next;
#ifndef DEDICATED_ONLY #ifndef DEDICATED_ONLY
// Write the config. Otherwise changes made by the // Write the config. Otherwise changes made by the
@ -1705,28 +1750,7 @@ FS_BuildGameSpecificSearchPath(char *dir)
// We may already have specialised directories in our search // We may already have specialised directories in our search
// path. This can happen if the server changes the mod. Let's // path. This can happen if the server changes the mod. Let's
// remove them. // remove them.
while (fs_searchPaths != fs_baseSearchPaths) fs_searchPaths = FS_FreeSearchPaths(fs_searchPaths, fs_baseSearchPaths);
{
if (fs_searchPaths->pack)
{
if (fs_searchPaths->pack->pak)
{
fclose(fs_searchPaths->pack->pak);
}
if (fs_searchPaths->pack->pk3)
{
unzClose(fs_searchPaths->pack->pk3);
}
Z_Free(fs_searchPaths->pack->files);
Z_Free(fs_searchPaths->pack);
}
next = fs_searchPaths->next;
Z_Free(fs_searchPaths);
fs_searchPaths = next;
}
/* Close open files for game dir. */ /* Close open files for game dir. */
for (i = 0; i < MAX_HANDLES; i++) for (i = 0; i < MAX_HANDLES; i++)
@ -1944,3 +1968,13 @@ FS_InitFilesystem(void)
// Debug output // Debug output
Com_Printf("Using '%s' for writing.\n", fs_gamedir); Com_Printf("Using '%s' for writing.\n", fs_gamedir);
} }
void
FS_ShutdownFilesystem(void)
{
fs_searchPaths = FS_FreeSearchPaths(fs_searchPaths, NULL);
fs_rawPath = FS_FreeRawPaths(fs_rawPath, NULL);
fs_baseSearchPaths = NULL;
}

View file

@ -67,6 +67,7 @@ int curtime;
#ifndef DEDICATED_ONLY #ifndef DEDICATED_ONLY
void Key_Init(void); void Key_Init(void);
void Key_Shutdown(void);
void SCR_EndLoadingPlaque(void); void SCR_EndLoadingPlaque(void);
#endif #endif
@ -764,5 +765,12 @@ Qcommon_Frame(int usec)
void void
Qcommon_Shutdown(void) Qcommon_Shutdown(void)
{ {
FS_ShutdownFilesystem();
Cvar_Fini(); Cvar_Fini();
#ifndef DEDICATED_ONLY
Key_Shutdown();
#endif
Cmd_Shutdown();
} }

View file

@ -355,6 +355,7 @@ void Cbuf_InsertFromDefer(void);
typedef void (*xcommand_t)(void); typedef void (*xcommand_t)(void);
void Cmd_Init(void); void Cmd_Init(void);
void Cmd_Shutdown(void);
void Cmd_AddCommand(char *cmd_name, xcommand_t function); void Cmd_AddCommand(char *cmd_name, xcommand_t function);
@ -677,6 +678,7 @@ char **FS_ListFiles2(char *findname, int *numfiles,
void FS_FreeList(char **list, int nfiles); void FS_FreeList(char **list, int nfiles);
void FS_InitFilesystem(void); void FS_InitFilesystem(void);
void FS_ShutdownFilesystem(void);
void FS_BuildGameSpecificSearchPath(char *dir); void FS_BuildGameSpecificSearchPath(char *dir);
char *FS_Gamedir(void); char *FS_Gamedir(void);
char *FS_NextPath(char *prevpath); char *FS_NextPath(char *prevpath);