pidgin: 3cdbd8e6: Fix leaks, and a bug.

sadrul at pidgin.im sadrul at pidgin.im
Thu Oct 8 20:07:36 EDT 2009


-----------------------------------------------------------------
Revision: 3cdbd8e68d755d394c112d467ece3a9db97931cf
Ancestor: ecbb67fb8ee3a827f7d9732a5236fed62fd75daa
Author: sadrul at pidgin.im
Date: 2009-10-08T18:10:48
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/3cdbd8e68d755d394c112d467ece3a9db97931cf

Modified files:
        finch/plugins/gnttinyurl.c

ChangeLog: 

Fix leaks, and a bug.

The bug: A message containing a short URL first would make it so other
longer URLs in the message will not be tinyurl-ed.

-------------- next part --------------
============================================================
--- finch/plugins/gnttinyurl.c	1eb8540aef7bf6671fecbe1598ad444b53490465
+++ finch/plugins/gnttinyurl.c	762feefac28f88d3e69dd9f37be2fb441e8705b9
@@ -148,7 +148,9 @@ static GList *extract_urls(const char *t
 					url_buf = g_strndup(c, t - c);
 					if (!g_list_find_custom(ret, url_buf, (GCompareFunc)strcmp)) {
 						purple_debug_info("TinyURL", "Added URL %s\n", url_buf);
-						ret = g_list_append(ret, g_strdup(url_buf));
+						ret = g_list_append(ret, url_buf);
+					} else {
+						g_free(url_buf);
 					}
 					c = t;
 					break;
@@ -179,6 +181,8 @@ static GList *extract_urls(const char *t
 						if (!g_list_find_custom(ret, url_buf, (GCompareFunc)strcmp)) {
 							purple_debug_info("TinyURL", "Added URL %s\n", url_buf);
 							ret = g_list_append(ret, url_buf);
+						} else {
+							g_free(url_buf);
 						}
 						c = t;
 						break;
@@ -231,7 +235,7 @@ static gboolean writing_msg(PurpleAccoun
 				PurpleConversation *conv, PurpleMessageFlags flags)
 {
 	GString *t;
-	GList *iter, *urls;
+	GList *iter, *urls, *next;
 	int c = 0;
 
 	if ((flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_INVISIBLE)))
@@ -247,7 +251,8 @@ static gboolean writing_msg(PurpleAccoun
 
 	t = g_string_new(*message);
 	g_free(*message);
-	for (iter = urls; iter; iter = iter->next) {
+	for (iter = urls; iter; iter = next) {
+		next = iter->next;
 		if (g_utf8_strlen((char *)iter->data, -1) >= purple_prefs_get_int(PREF_LENGTH)) {
 			int pos, x = 0;
 			gchar *j, *s, *str, *orig;
@@ -265,15 +270,8 @@ static gboolean writing_msg(PurpleAccoun
 			g_free(str);
 			continue;
 		} else {
-			if (iter->prev) {
-				iter = iter->prev;
-				g_free(iter->next->data);
-				urls = g_list_delete_link(urls, iter->next);
-			} else {
-				g_free(iter->data);
-				g_list_free(urls);
-				urls = NULL;
-			}
+			g_free(iter->data);
+			urls = g_list_delete_link(urls, iter);
 		}
 	}
 	*message = t->str;


More information about the Commits mailing list