summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2005-01-31 23:33:59 +0000
committerSebastien Helleu <flashcode@flashtux.org>2005-01-31 23:33:59 +0000
commit8921e45815b15d27976eb6f1bc8339d71eca640d (patch)
tree2e224ac97ed29ab21ab8f95396227a4d6b1e82c9 /src/common
parent74b83e52940e35a9a2f9ee6177775d067fef502c (diff)
downloadweechat-8921e45815b15d27976eb6f1bc8339d71eca640d.zip
Fixed many memory leaks
Diffstat (limited to 'src/common')
-rw-r--r--src/common/command.c24
-rw-r--r--src/common/command.h2
-rw-r--r--src/common/history.c47
-rw-r--r--src/common/history.h2
-rw-r--r--src/common/weechat.c44
-rw-r--r--src/common/weechat.h2
6 files changed, 106 insertions, 15 deletions
diff --git a/src/common/command.c b/src/common/command.c
index b24d14e3a..7b7cb68ba 100644
--- a/src/common/command.c
+++ b/src/common/command.c
@@ -146,6 +146,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
*/
@@ -307,6 +320,17 @@ alias_free (t_weechat_alias *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
*/
diff --git a/src/common/command.h b/src/common/command.h
index 44a2a913b..474f3c10c 100644
--- a/src/common/command.h
+++ b/src/common/command.h
@@ -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 *);
diff --git a/src/common/history.c b/src/common/history.c
index 116e7f31c..ece23fdd7 100644
--- a/src/common/history.c
+++ b/src/common/history.c
@@ -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;
+}
diff --git a/src/common/history.h b/src/common/history.h
index 652d206ca..9be1b40e8 100644
--- a/src/common/history.h
+++ b/src/common/history.h
@@ -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 */
diff --git a/src/common/weechat.c b/src/common/weechat.c
index b5629268a..c1e85e4e0 100644
--- a/src/common/weechat.c
+++ b/src/common/weechat.c
@@ -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) */
}
diff --git a/src/common/weechat.h b/src/common/weechat.h
index 95e5a1fad..16504a3d3 100644
--- a/src/common/weechat.h
+++ b/src/common/weechat.h
@@ -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 */