diff options
author | bviktor <bviktor@outlook.com> | 2012-10-02 13:02:17 -0700 |
---|---|---|
committer | bviktor <bviktor@outlook.com> | 2012-10-02 13:02:17 -0700 |
commit | c80858f919cd54b3f6721d2267b33dc3a91da474 (patch) | |
tree | c0b9de69542f9b6ebb7164edc88a59c45a786aa6 /src/common/url.c | |
parent | 6e3efe262258204b8c0a5c1c3260e93c2588c20d (diff) | |
parent | 62903cd171acb49ed66056c32edbcc0fd56b07c5 (diff) |
Merge pull request #115 from RichardHitt/master
Fix memory leak related to url grabbing
Diffstat (limited to 'src/common/url.c')
-rw-r--r-- | src/common/url.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/common/url.c b/src/common/url.c index 2f09ad3c..31a45d49 100644 --- a/src/common/url.c +++ b/src/common/url.c @@ -31,6 +31,7 @@ #endif void *url_tree = NULL; +GTree *url_btree = NULL; static int @@ -46,6 +47,8 @@ url_clear (void) tree_foreach (url_tree, (tree_traverse_func *)url_free, NULL); tree_destroy (url_tree); url_tree = NULL; + g_tree_destroy (url_btree); + url_btree = NULL; } static int @@ -80,11 +83,7 @@ url_autosave (void) static int url_find (char *urltext) { - int pos; - - if (tree_find (url_tree, urltext, (tree_cmp_func *)g_ascii_strcasecmp, NULL, &pos)) - return 1; - return 0; + return (g_tree_lookup_extended (url_btree, urltext, NULL, NULL)); } static void @@ -110,15 +109,18 @@ url_add (char *urltext, int len) if (data[len - 1] == ')') /* chop trailing ) */ data[len - 1] = 0; + if (!url_tree) + { + url_tree = tree_new ((tree_cmp_func *)strcasecmp, NULL); + url_btree = g_tree_new ((GCompareFunc)strcasecmp); + } + if (url_find (data)) { free (data); return; } - if (!url_tree) - url_tree = tree_new ((tree_cmp_func *)g_ascii_strcasecmp, NULL); - size = tree_size (url_tree); /* 0 is unlimited */ if (prefs.url_grabber_limit > 0 && size >= prefs.url_grabber_limit) @@ -127,10 +129,17 @@ url_add (char *urltext, int len) xchat is running */ size -= prefs.url_grabber_limit; for(; size > 0; size--) - tree_remove_at_pos (url_tree, 0); + { + char *pos; + + pos = tree_remove_at_pos (url_tree, 0); + g_tree_remove (url_btree, pos); + free (pos); + } } tree_append (url_tree, data); + g_tree_insert (url_btree, data, GINT_TO_POINTER (tree_size (url_tree) - 1)); fe_url_add (data); } |