[console] Plug more memory leaks

This commit is contained in:
Bill Currie 2023-03-05 17:10:04 +09:00
parent 3d65376f87
commit 3f9873a754
6 changed files with 53 additions and 18 deletions

View file

@ -110,6 +110,7 @@ void C_DrawInputLine (struct inputline_s *il);
struct view_s; struct view_s;
void Menu_Init (void); void Menu_Init (void);
void Menu_Shutdown (void);
void Menu_Load (void); void Menu_Load (void);
void Menu_Draw (struct view_s view); void Menu_Draw (struct view_s view);
void Menu_Draw_Hud (struct view_s view); void Menu_Draw_Hud (struct view_s view);

View file

@ -105,7 +105,9 @@ bi_il_clear (progs_t *pr, void *_res)
static void static void
bi_il_destroy (progs_t *pr, void *_res) bi_il_destroy (progs_t *pr, void *_res)
{ {
free (_res); il_resources_t *res = _res;
PR_RESDELMAP (res->line_map);
free (res);
} }
static il_data_t * __attribute__((pure)) static il_data_t * __attribute__((pure))

View file

@ -160,6 +160,10 @@ static int con_saved_focos;
static qboolean con_debuglog; static qboolean con_debuglog;
static qboolean chat_team; static qboolean chat_team;
static dstring_t *c_print_buffer;
static dstring_t *dlbar;
static dstring_t *old_gamedir = 0;
typedef struct { typedef struct {
const char *prompt; const char *prompt;
@ -448,26 +452,25 @@ static __attribute__((format(PRINTF, 1, 0))) void
C_Print (const char *fmt, va_list args) C_Print (const char *fmt, va_list args)
{ {
char *s; char *s;
static dstring_t *buffer;
int mask, c; int mask, c;
if (!buffer) if (!c_print_buffer)
buffer = dstring_new (); c_print_buffer = dstring_new ();
dvsprintf (buffer, fmt, args); dvsprintf (c_print_buffer, fmt, args);
// log all messages to file // log all messages to file
if (con_debuglog) if (con_debuglog)
Sys_DebugLog (va (0, "%s/%s/qconsole.log", qfs_userpath,//FIXME Sys_DebugLog (va (0, "%s/%s/qconsole.log", qfs_userpath,//FIXME
qfs_gamedir->dir.def), "%s", buffer->str); qfs_gamedir->dir.def), "%s", c_print_buffer->str);
if (!con_initialized) if (!con_initialized)
return; return;
s = buffer->str; s = c_print_buffer->str;
mask = 0; mask = 0;
if (buffer->str[0] == 1 || buffer->str[0] == 2) { if (s[0] == 1 || s[0] == 2) {
mask = 128; // go to colored text mask = 128; // go to colored text
s++; s++;
} }
@ -506,10 +509,10 @@ C_Print (const char *fmt, va_list args)
// echo to debugging console // echo to debugging console
// but don't print the highchars flag (leading \x01) // but don't print the highchars flag (leading \x01)
if ((byte)buffer->str[0] > 2) if ((byte)c_print_buffer->str[0] > 2)
fputs (buffer->str, stdout); fputs (c_print_buffer->str, stdout);
else if ((byte)buffer->str[0]) else if ((byte)c_print_buffer->str[0])
fputs (buffer->str + 1, stdout); fputs (c_print_buffer->str + 1, stdout);
} }
/* DRAWING */ /* DRAWING */
@ -582,7 +585,6 @@ resize_input (view_t view, view_pos_t len)
static void static void
update_download (void) update_download (void)
{ {
static dstring_t *dlbar;
const char *text; const char *text;
if (!dlbar) { if (!dlbar) {
@ -815,8 +817,6 @@ C_DrawConsole (void)
static void static void
C_NewMap (void) C_NewMap (void)
{ {
static dstring_t *old_gamedir = 0;
if (!old_gamedir || !strequal (old_gamedir->str, qfs_gamedir->gamedir)) if (!old_gamedir || !strequal (old_gamedir->str, qfs_gamedir->gamedir))
Menu_Load (); Menu_Load ();
if (!old_gamedir) if (!old_gamedir)
@ -1193,7 +1193,32 @@ C_Init (void)
static void static void
C_shutdown (void) C_shutdown (void)
{ {
r_funcs->Draw_DestroyPic (conback);
IE_Remove_Handler (con_event_id); IE_Remove_Handler (con_event_id);
Menu_Shutdown ();
Con_DestroyInputLine (cmd_line.input_line);
Con_DestroyInputLine (team_input);
Con_DestroyInputLine (chat_input);
Con_DestroyBuffer (con_main);
if (download_buffer) {
Draw_DestroyBuffer (download_buffer);
}
Draw_DestroyBuffer (console_buffer);
Draw_DestroyBuffer (cmd_line.buffer);
Draw_DestroyBuffer (notify_buffer);
Draw_DestroyBuffer (say_line.buffer);
if (c_print_buffer) {
dstring_delete (c_print_buffer);
}
if (dlbar) {
dstring_delete (dlbar);
}
if (old_gamedir) {
dstring_delete (old_gamedir);
}
} }
static general_data_t plugin_info_general_data; static general_data_t plugin_info_general_data;

View file

@ -102,7 +102,6 @@ Con_shutdown (void *data)
Sys_SetStdPrintf (saved_sys_printf); Sys_SetStdPrintf (saved_sys_printf);
} }
if (con_module) { if (con_module) {
con_module->functions->general->shutdown ();
PI_UnloadPlugin (con_module); PI_UnloadPlugin (con_module);
} }
} }

View file

@ -99,7 +99,7 @@ static pr_func_t menu_quit;
static pr_func_t menu_draw_hud; static pr_func_t menu_draw_hud;
static pr_func_t menu_pre; static pr_func_t menu_pre;
static pr_func_t menu_post; static pr_func_t menu_post;
static const char *top_menu; static char *top_menu;
typedef struct menu_func_s { typedef struct menu_func_s {
const char *name; const char *name;
@ -365,7 +365,7 @@ bi_Menu_TopMenu (progs_t *pr, void *data)
const char *name = P_GSTRING (pr, 0); const char *name = P_GSTRING (pr, 0);
if (top_menu) if (top_menu)
free ((char *) top_menu); free (top_menu);
top_menu = strdup (name); top_menu = strdup (name);
} }
@ -591,6 +591,13 @@ Menu_Next_f (void)
Menu_KeyEvent (QFK_DOWN, '\0', true); Menu_KeyEvent (QFK_DOWN, '\0', true);
} }
void
Menu_Shutdown (void)
{
PR_Shutdown (&menu_pr_state);
Hash_DelTable (menu_hash);
free (top_menu);
}
void void
Menu_Init (void) Menu_Init (void)

View file

@ -161,6 +161,7 @@ event_handler (const IE_event_t *ie_event, void *_pr)
static void static void
BI_shutdown (void *data) BI_shutdown (void *data)
{ {
ECS_DelRegistry (canvas_sys.reg);
} }
static byte default_palette[256][3]; static byte default_palette[256][3];