1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 11:13:12 +02:00

Fixed many memory leaks

This commit is contained in:
Sebastien Helleu
2005-01-31 23:33:59 +00:00
parent 74b83e5294
commit 8921e45815
26 changed files with 314 additions and 44 deletions
+24
View File
@@ -145,6 +145,19 @@ command_index_build ()
}
}
/*
* command_index_free: remove all commands in index
*/
void
command_index_free ()
{
while (index_commands)
{
weelist_remove (&index_commands, &last_index_command, index_commands);
}
}
/*
* alias_search: search an alias
*/
@@ -306,6 +319,17 @@ alias_free (t_weechat_alias *alias)
weechat_alias = new_weechat_alias;
}
/*
* alias_free_all: free all alias
*/
void
alias_free_all ()
{
while (weechat_alias)
alias_free (weechat_alias);
}
/*
* explode_string: explode a string according to separators
*/
+2
View File
@@ -56,7 +56,9 @@ extern t_weelist *index_commands;
extern t_weelist *last_index_command;
extern void command_index_build ();
extern void command_index_free ();
extern t_weechat_alias *alias_new (char *, char *);
extern void alias_free_all ();
extern int exec_weechat_command (t_irc_server *, char *);
extern void user_command (t_irc_server *, char *);
extern int weechat_cmd_alias (char *);
+47
View File
@@ -136,3 +136,50 @@ history_add (void *buffer, char *string)
}
}
}
/*
* history_general_free: free general history
*/
void
history_general_free ()
{
t_history *ptr_history;
while (history_general)
{
ptr_history = history_general->next_history;
if (history_general->text)
free (history_general->text);
free (history_general);
history_general = ptr_history;
}
history_general = NULL;
history_general_last = NULL;
history_general_ptr = NULL;
num_history_general = 0;
}
/*
* history_buffer_free: free history for a buffer
*/
void
history_buffer_free (void *buffer)
{
t_history *ptr_history;
while (((t_gui_buffer *)(buffer))->history)
{
ptr_history = ((t_gui_buffer *)(buffer))->history->next_history;
if (((t_gui_buffer *)(buffer))->history->text)
free (((t_gui_buffer *)(buffer))->history->text);
free (((t_gui_buffer *)(buffer))->history);
((t_gui_buffer *)(buffer))->history = ptr_history;
}
((t_gui_buffer *)(buffer))->history = NULL;
((t_gui_buffer *)(buffer))->last_history = NULL;
((t_gui_buffer *)(buffer))->ptr_history = NULL;
((t_gui_buffer *)(buffer))->num_history = 0;
}
+2
View File
@@ -31,5 +31,7 @@ struct t_history
};
extern void history_add (void *, char *);
extern void history_general_free ();
extern void history_buffer_free (void *);
#endif /* history.h */
+30 -14
View File
@@ -60,9 +60,9 @@
#include "../plugins/plugins.h"
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
char *weechat_home; /* WeeChat home dir. (example: /home/toto/.weechat) */
FILE *weechat_log_file; /* WeeChat log file (~/.weechat/weechat.log) */
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
char *weechat_home = NULL; /* WeeChat home dir. (example: /home/toto/.weechat) */
FILE *weechat_log_file = NULL; /* WeeChat log file (~/.weechat/weechat.log) */
char *local_charset = NULL; /* local charset, for example: ISO-8859-1 */
@@ -264,26 +264,26 @@ wee_parse_args (int argc, char *argv[])
|| (strcmp (argv[i], "--config") == 0))
{
wee_display_config_options ();
exit (EXIT_SUCCESS);
wee_shutdown (EXIT_SUCCESS);
}
else if ((strcmp (argv[i], "-h") == 0)
|| (strcmp (argv[i], "--help") == 0))
{
printf ("\n" WEE_USAGE1, argv[0], argv[0]);
printf ("%s", WEE_USAGE2);
exit (EXIT_SUCCESS);
wee_shutdown (EXIT_SUCCESS);
}
else if ((strcmp (argv[i], "-l") == 0)
|| (strcmp (argv[i], "--license") == 0))
{
printf ("\n%s%s", WEE_LICENSE);
exit (EXIT_SUCCESS);
wee_shutdown (EXIT_SUCCESS);
}
else if ((strcmp (argv[i], "-v") == 0)
|| (strcmp (argv[i], "--version") == 0))
{
printf (PACKAGE_VERSION "\n");
exit (EXIT_SUCCESS);
wee_shutdown (EXIT_SUCCESS);
}
else if ((strncasecmp (argv[i], "irc://", 6) == 0))
{
@@ -358,7 +358,7 @@ wee_create_home_dirs ()
{
fprintf (stderr, _("%s unable to get HOME directory\n"),
WEECHAT_ERROR);
exit (EXIT_FAILURE);
wee_shutdown (EXIT_FAILURE);
}
dir_length = strlen (ptr_home) + 10;
weechat_home =
@@ -367,7 +367,7 @@ wee_create_home_dirs ()
{
fprintf (stderr, _("%s not enough memory for home directory\n"),
WEECHAT_ERROR);
exit (EXIT_FAILURE);
wee_shutdown (EXIT_FAILURE);
}
snprintf (weechat_home, dir_length, "%s%s.weechat", ptr_home,
DIR_SEPARATOR);
@@ -377,7 +377,7 @@ wee_create_home_dirs ()
{
fprintf (stderr, _("%s unable to create ~/.weechat directory\n"),
WEECHAT_ERROR);
exit (EXIT_FAILURE);
wee_shutdown (EXIT_FAILURE);
}
dir_length = strlen (weechat_home) + 64;
@@ -509,18 +509,32 @@ weechat_welcome_message ()
}
/*
* wee_shutdown: shutdown WeeChat
* wee_gui_shutdown: shutdown WeeChat GUI
*/
void
wee_shutdown ()
wee_gui_shutdown ()
{
dcc_end ();
server_free_all ();
gui_end ();
}
/*
* wee_shutdown: shutdown WeeChat
*/
void
wee_shutdown (int return_code)
{
if (weechat_home)
free (weechat_home);
if (weechat_log_file)
fclose (weechat_log_file);
exit (EXIT_SUCCESS);
if (local_charset)
free (local_charset);
alias_free_all ();
exit (return_code);
}
/*
@@ -572,7 +586,9 @@ main (int argc, char *argv[])
plugin_end (); /* end plugin interface(s) */
server_disconnect_all (); /* disconnect from all servers */
(void) config_write (NULL); /* save config file */
wee_shutdown (); /* quit WeeChat (oh no, why?) */
command_index_free (); /* free commands index */
wee_gui_shutdown (); /* shut down WeeChat GUI */
wee_shutdown (EXIT_SUCCESS); /* quit WeeChat (oh no, why?) */
return EXIT_SUCCESS; /* make gcc happy (never executed) */
}
+1 -1
View File
@@ -105,6 +105,6 @@ extern char *local_charset;
extern char *weechat_convert_encoding (char *, char *, char *);
extern long get_timeval_diff (struct timeval *, struct timeval *);
extern void wee_log_printf (char *, ...);
extern void wee_shutdown ();
extern void wee_shutdown (int);
#endif /* weechat.h */