changeset 23852:a1a1f44cdecc

Fixed some memory leak issues involving GLists.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Fri, 11 Jul 2008 02:10:04 +0000
parents 5736b1881bf4
children 8c4bc05513c7
files libpurple/media.c libpurple/protocols/jabber/jingle.c pidgin/gtkmedia.c
diffstat 3 files changed, 10 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/media.c	Fri Jul 11 01:35:54 2008 +0000
+++ b/libpurple/media.c	Fri Jul 11 02:10:04 2008 +0000
@@ -337,12 +337,11 @@
 	GList *values = g_hash_table_get_values(media->priv->sessions);
 	PurpleMediaStreamType type = PURPLE_MEDIA_NONE;
 
-	for (; values; values = values->next) {
+	for (; values; values = g_list_delete_link(values, values)) {
 		PurpleMediaSession *session = values->data;
 		type |= session->type;
 	}
 
-	g_list_free(values);
 	return type;
 }
 
@@ -458,7 +457,7 @@
 {
 	GList *values = g_hash_table_get_values(media->priv->sessions);
 
-	for (; values; values = values->next) {
+	for (; values; values = g_list_delete_link(values, values)) {
 		PurpleMediaSession *session = (PurpleMediaSession*)values->data;
 
 		if (session->type & PURPLE_MEDIA_SEND_AUDIO && audio_src)
@@ -470,8 +469,6 @@
 		if (session->type & PURPLE_MEDIA_RECV_VIDEO && video_sink)
 			*video_sink = session->sink;
 	}
-
-	g_list_free(values);
 }
 
 void 
--- a/libpurple/protocols/jabber/jingle.c	Fri Jul 11 01:35:54 2008 +0000
+++ b/libpurple/protocols/jabber/jingle.c	Fri Jul 11 02:10:04 2008 +0000
@@ -250,17 +250,17 @@
 static void
 jabber_jingle_session_destroy(JingleSession *sess)
 {
-	GList *contents = g_hash_table_get_values(sess->contents);
+	GList *contents;
 	g_hash_table_remove(sess->js->sessions, sess->id);
 	g_free(sess->id);
 
 	if (sess->media)
 		g_object_unref(sess->media);
 
-	for (; contents; contents = contents->next)
+	for (contents = g_hash_table_get_values(sess->contents); contents;
+			contents = g_list_delete_link(contents, contents))
 		jabber_jingle_session_destroy_content(contents->data);
 
-	g_list_free(contents);
 	g_free(sess);
 }
 
@@ -278,11 +278,10 @@
 jabber_jingle_session_find_by_jid(JabberStream *js, const char *jid)
 {
 	GList *values = g_hash_table_get_values(js->sessions);
-	GList *iter = values;
 	gboolean use_bare = strchr(jid, '/') == NULL;
 
-	for (; iter; iter = iter->next) {
-		JingleSession *session = (JingleSession *)iter->data;
+	for (; values; values = g_list_delete_link(values, values)) {
+		JingleSession *session = (JingleSession *)values->data;
 		gchar *cmp_jid = use_bare ? jabber_get_bare_jid(session->remote_jid)
 					  : g_strdup(session->remote_jid);
 		if (!strcmp(jid, cmp_jid)) {
@@ -293,7 +292,6 @@
 		g_free(cmp_jid);
 	}
 
-	g_list_free(values);
 	return NULL;	
 }
 
@@ -947,7 +945,7 @@
 		return FALSE;
 	}
 
-	for (; contents; contents = contents->next) {
+	for (; contents; contents = g_list_delete_link(contents, contents)) {
 		JingleSessionContent *jsc = contents->data;
 		gboolean result = FALSE;
 
@@ -969,7 +967,6 @@
 			return FALSE;
 		}
 	}
-	g_list_free(contents);
 
 	jabber_jingle_session_set_remote_jid(session, remote_jid);
 	jabber_jingle_session_set_initiator(session, initiator);
@@ -1115,12 +1112,10 @@
 	GList *values = js->sessions ?
 			g_hash_table_get_values(js->sessions) : NULL;
 
-	for (; values; values = values->next) {
+	for (; values; values = g_list_delete_link(values, values)) {
 		JingleSession *session = (JingleSession *)values->data;
 		purple_media_hangup(session->media);
 	}
-
-	g_list_free(values);
 }
 
 static void
--- a/pidgin/gtkmedia.c	Fri Jul 11 01:35:54 2008 +0000
+++ b/pidgin/gtkmedia.c	Fri Jul 11 02:10:04 2008 +0000
@@ -298,7 +298,7 @@
 	GList *sessions = purple_media_get_session_names(media);
 	GstBus *bus;
 
-	for (; sessions; sessions = sessions->next) {
+	for (; sessions; sessions = g_list_delete_link(sessions, sessions)) {
 		if (purple_media_get_session_type(media, sessions->data) & PURPLE_MEDIA_AUDIO) {
 			if (!audiosendbin)
 				purple_media_audio_init_src(&audiosendbin, &audiosendlevel);
@@ -315,7 +315,6 @@
 			purple_media_set_sink(media, sessions->data, videorecvbin);
 		}
 	}
-	g_list_free(sessions);
 
 	if (audiosendlevel && audiorecvlevel) {
 		g_object_set(gtkmedia, "send-level", audiosendlevel,