mcedit reentrancy and memory leaks in dir.c
- From: "Andrew V. Samoilov" <andrew email zp ua>
- To: mc-devel gnome org
- Subject: mcedit reentrancy and memory leaks in dir.c
- Date: Thu, 23 Oct 2003 23:10:20 +0300 (EEST)
Hello,
two patches to improve mcedit reentrancy and to fix some possible memory leaks
in src/dir.c. BTW, what about moving tree_store_start_check_cwd() in do_(re)load_dir() after mc_opendir() to eliminate one tree_store_end_check() ?
--
Regards,
Andrew V. Samoilov.
src/ChangeLog:
* dir.c (do_reload_dir): Fix memory leaks.
--- dir.c~ Wed Oct 15 16:21:03 2003
+++ dir.c Thu Oct 23 22:36:53 2003
@@ -576,7 +576,7 @@ do_reload_dir (char *path, dir_list *lis
int i, status, link_to_dir, stale_link;
struct stat st;
int marked_cnt;
- GHashTable *marked_files = g_hash_table_new (g_str_hash, g_str_equal);
+ GHashTable *marked_files;
tree_store_start_check_cwd ();
dirp = mc_opendir (".");
@@ -587,6 +587,7 @@ do_reload_dir (char *path, dir_list *lis
return set_zero_dir (list);
}
+ marked_files = g_hash_table_new (g_str_hash, g_str_equal);
alloc_dir_copy (list->size);
for (marked_cnt = i = 0; i < count; i++) {
dir_copy.list[i].fnamelen = list->list[i].fnamelen;
@@ -603,7 +604,7 @@ do_reload_dir (char *path, dir_list *lis
}
}
- for (dp = mc_readdir (dirp); dp; dp = mc_readdir (dirp)) {
+ while ((dp = mc_readdir (dirp)) {
status =
handle_dirent (list, filter, dp, &st, next_free, &link_to_dir,
&stale_link);
@@ -622,6 +623,7 @@ do_reload_dir (char *path, dir_list *lis
clean_dir (&dir_copy, count);
*/
tree_store_end_check ();
+ g_hash_table_destroy (marked_files);
return next_free;
}
edit/ChangeLog:
* edit-widget.h (struct WEdit): Add GTree *defines field.
* syntax.c: Use edit->defines instead of static defines.
--- edit/edit-widget.h
+++ edit/edit-widget.h
@@ -95,6 +95,7 @@
long last_get_rule;
struct syntax_rule rule;
char *syntax_type; /* description of syntax highlighting type being used */
+ GTree *defines; /* List of defines */
/* macro stuff */
int macro_i; /* index to macro[], -1 if not recording a macro */
--- edit/syntax.c Thu Oct 23 22:51:34 2003
+++ edit/syntax.c Thu Oct 23 20:10:08 2003
@@ -88,9 +88,6 @@ int option_syntax_highlighting = 1;
#define syntax_g_free(x) do {if(x) {g_free(x); (x)=0;}} while (0)
-/* List of defines */
-static GTree *defines;
-
static gint
mc_defines_destroy (gpointer key, gpointer value, gpointer data)
{
@@ -106,11 +103,11 @@ mc_defines_destroy (gpointer key, gpoint
/* Completely destroys the defines tree */
static inline void
-destroy_defines (void)
+destroy_defines (GTree **defines)
{
- g_tree_traverse (defines, mc_defines_destroy, G_POST_ORDER, NULL);
- g_tree_destroy (defines);
- defines = 0;
+ g_tree_traverse (*defines, mc_defines_destroy, G_POST_ORDER, NULL);
+ g_tree_destroy (*defines);
+ *defines = 0;
}
static void
@@ -667,8 +664,8 @@ edit_read_syntax_rules (WEdit *edit, FIL
r = edit->rules = g_malloc0 (MAX_CONTEXTS * sizeof (struct context_rule *));
- if (!defines)
- defines = g_tree_new ((GCompareFunc) strcmp);
+ if (!edit->defines)
+ edit->defines = g_tree_new ((GCompareFunc) strcmp);
for (;;) {
char **a;
@@ -777,7 +774,7 @@ edit_read_syntax_rules (WEdit *edit, FIL
#endif
num_words = 1;
c->keyword[0] = g_malloc0 (sizeof (struct key_word));
- subst_defines (defines, a, &args[1024]);
+ subst_defines (edit->defines, a, &args[1024]);
fg = *a;
if (*a)
a++;
@@ -826,7 +823,7 @@ edit_read_syntax_rules (WEdit *edit, FIL
}
k->keyword = g_strdup (*a++);
k->first = *k->keyword;
- subst_defines (defines, a, &args[1024]);
+ subst_defines (edit->defines, a, &args[1024]);
fg = *a;
if (*a)
a++;
@@ -850,13 +847,13 @@ edit_read_syntax_rules (WEdit *edit, FIL
if (argc < 3)
break_a;
- if ((argv = g_tree_lookup (defines, key))) {
+ if ((argv = g_tree_lookup (edit->defines, key))) {
mc_defines_destroy (NULL, argv, NULL);
} else {
key = g_strdup (key);
}
argv = g_new (char *, argc - 1);
- g_tree_insert (defines, key, argv);
+ g_tree_insert (edit->defines, key, argv);
while (*a) {
*argv++ = g_strdup (*a++);
};
@@ -901,8 +898,8 @@ void edit_free_syntax_rules (WEdit * edi
int i, j;
if (!edit)
return;
- if (defines)
- destroy_defines ();
+ if (edit->defines)
+ destroy_defines (&edit->defines);
if (!edit->rules)
return;
edit_get_rule (edit, -1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]