soc.2008.vv: 3a78233b: Fixed a ton of memory leaks.

maiku at soc.pidgin.im maiku at soc.pidgin.im
Mon Aug 18 02:30:46 EDT 2008


-----------------------------------------------------------------
Revision: 3a78233bf1c7dba3fc3750e55a55ec3656f02b29
Ancestor: bb73132004250dfcf6701c32d6a094c5f6877757
Author: maiku at soc.pidgin.im
Date: 2008-08-18T06:25:38
Branch: im.pidgin.soc.2008.vv
URL: http://d.pidgin.im/viewmtn/revision/info/3a78233bf1c7dba3fc3750e55a55ec3656f02b29

Modified files:
        libpurple/media.c libpurple/protocols/jabber/jingle.c
        pidgin/gtkconv.c pidgin/gtkmedia.c pidgin/gtkprefs.c

ChangeLog: 

Fixed a ton of memory leaks.

-------------- next part --------------
============================================================
--- libpurple/media.c	f2f73aa2062dbd6a374a4a3df4d80dfd57d7cdb4
+++ libpurple/media.c	c83fe6ee9b83f348e7dfd32c5a449076ef7c7b92
@@ -47,9 +47,11 @@ struct _PurpleMediaSession
 	GstElement *src;
 	GstElement *sink;
 	FsSession *session;
-	GHashTable *streams;		/* FsStream list map to participant's name */
+	/* FsStream table. Mapped by participant's name */
+	GHashTable *streams;
 	PurpleMediaSessionType type;
-	GHashTable *local_candidates;	/* map to participant's name? */
+	/* GList of FsCandidates table. Mapped by participant's name */
+	GHashTable *local_candidates;
 
 	/*
 	 * These will need to be per stream when sessions with multiple
@@ -221,7 +223,6 @@ purple_media_finalize (GObject *media)
 purple_media_finalize (GObject *media)
 {
 	PurpleMediaPrivate *priv = PURPLE_MEDIA_GET_PRIVATE(media);
-	GList *sessions = g_hash_table_get_values(priv->sessions);
 	purple_debug_info("media","purple_media_finalize\n");
 
 	purple_media_manager_remove_media(purple_media_manager_get(),
@@ -229,15 +230,42 @@ purple_media_finalize (GObject *media)
 
 	g_free(priv->name);
 
-	for (; sessions; sessions = g_list_delete_link(sessions, sessions)) {
-		PurpleMediaSession *session = sessions->data;
-		GList *streams = g_hash_table_get_values(session->streams);
+	if (priv->sessions) {
+		GList *sessions = g_hash_table_get_values(priv->sessions);
+		for (; sessions; sessions = g_list_delete_link(sessions, sessions)) {
+			PurpleMediaSession *session = sessions->data;
+			g_free(session->id);
 
-		for (; streams; streams = g_list_delete_link(streams, streams)) {
-			g_object_unref(streams->data);
+			if (session->streams) {
+				GList *streams = g_hash_table_get_values(session->streams);
+				for (; streams; streams = g_list_delete_link(streams, streams))
+					g_object_unref(streams->data);
+				g_hash_table_destroy(session->streams);
+			}
+
+			if (session->local_candidates) {
+				GList *candidates = g_hash_table_get_values(session->local_candidates);
+				for (; candidates; candidates =
+						g_list_delete_link(candidates, candidates))
+					fs_candidate_list_destroy(candidates->data);
+				g_hash_table_destroy(session->local_candidates);
+			}
+
+			if (session->local_candidate)
+				fs_candidate_destroy(session->local_candidate);
+			if (session->remote_candidate)
+				fs_candidate_destroy(session->remote_candidate);
+
+			g_free(session);
 		}
+		g_hash_table_destroy(priv->sessions);
+	}
 
-		g_object_unref(session->session);
+	if (priv->participants) {
+		GList *participants = g_hash_table_get_values(priv->participants);
+		for (; participants; participants = g_list_delete_link(participants, participants))
+			g_object_unref(participants->data);
+		g_hash_table_destroy(priv->participants);
 	}
 
 	if (priv->pipeline) {
@@ -416,7 +444,7 @@ purple_media_add_participant(PurpleMedia
 		return participant;
 
 	participant = fs_conference_new_participant(media->priv->conference,
-						    g_strdup(name), &err);
+						    (gchar*)name, &err);
 
 	if (err) {
 		purple_debug_error("media", "Error creating participant: %s\n",
@@ -427,7 +455,8 @@ purple_media_add_participant(PurpleMedia
 
 	if (!media->priv->participants) {
 		purple_debug_info("media", "Creating hash table for participants\n");
-		media->priv->participants = g_hash_table_new(g_str_hash, g_str_equal);
+		media->priv->participants = g_hash_table_new_full(g_str_hash,
+				g_str_equal, g_free, NULL);
 	}
 
 	g_hash_table_insert(media->priv->participants, g_strdup(name), participant);
@@ -440,7 +469,8 @@ purple_media_insert_stream(PurpleMediaSe
 {
 	if (!session->streams) {
 		purple_debug_info("media", "Creating hash table for streams\n");
-		session->streams = g_hash_table_new(g_str_hash, g_str_equal);
+		session->streams = g_hash_table_new_full(g_str_hash,
+				g_str_equal, g_free, NULL);
 	}
 
 	g_hash_table_insert(session->streams, g_strdup(name), stream);
@@ -456,7 +486,8 @@ purple_media_insert_local_candidate(Purp
 
 	if (!session->local_candidates) {
 		purple_debug_info("media", "Creating hash table for local candidates\n");
-		session->local_candidates = g_hash_table_new(g_str_hash, g_str_equal);
+		session->local_candidates = g_hash_table_new_full(g_str_hash,
+				g_str_equal, g_free, NULL);
 	}
 
 	g_hash_table_insert(session->local_candidates, g_strdup(name), candidates);
@@ -716,12 +747,14 @@ purple_media_get_devices(GstElement *ele
 
 		array = gst_property_probe_probe_and_get_values (probe, pspec);
 		if (array != NULL) {
-
 			for (n = 0 ; n < array->n_values ; n++) {
 				GValue *device = g_value_array_get_nth (array, n);
+				GValue *location = g_new0(GValue, 1);
 				gst_element_set_state (element, GST_STATE_NULL);
+				location = g_value_init(location, G_TYPE_STRING);
 
-				ret = g_list_append(ret, device);
+				g_value_copy(device, location);
+				ret = g_list_append(ret, location);
 
 				name = purple_media_get_device_name(GST_ELEMENT(element), device);
 				purple_debug_info("media", "Found source '%s' (%s) - device '%s' (%s)\n",
@@ -729,6 +762,7 @@ purple_media_get_devices(GstElement *ele
 						  name, g_value_get_string(device));
 				g_free(name);
 			}
+			g_value_array_free(array);
 		}
 	}
 
@@ -916,6 +950,7 @@ purple_media_new_local_candidate_cb(FsSt
 {
 	gchar *name;
 	FsParticipant *participant;
+	FsCandidate *candidate;
 	purple_debug_info("media", "got new local candidate: %s\n", local_candidate->candidate_id);
 	g_object_get(stream, "participant", &participant, NULL);
 	g_object_get(participant, "cname", &name, NULL);
@@ -923,8 +958,10 @@ purple_media_new_local_candidate_cb(FsSt
 
 	purple_media_insert_local_candidate(session, name, fs_candidate_copy(local_candidate));
 
+	candidate = fs_candidate_copy(local_candidate);
 	g_signal_emit(session->media, purple_media_signals[NEW_CANDIDATE],
-		      0, session->id, name, fs_candidate_copy(local_candidate));
+		      0, session->id, name, candidate);
+	fs_candidate_destroy(candidate);
 
 	g_free(name);
 }
@@ -949,13 +986,18 @@ purple_media_candidate_pair_established_
 					   FsCandidate *remote_candidate,
 					   PurpleMediaSession *session)
 {
+	FsCandidate *local = fs_candidate_copy(native_candidate);
+	FsCandidate *remote = fs_candidate_copy(remote_candidate);
+
 	session->local_candidate = fs_candidate_copy(native_candidate);
 	session->remote_candidate = fs_candidate_copy(remote_candidate);
 
 	purple_debug_info("media", "candidate pair established\n");
 	g_signal_emit(session->media, purple_media_signals[CANDIDATE_PAIR], 0,
-		      session->local_candidate,
-		      session->remote_candidate);
+		      local, remote);
+
+	fs_candidate_destroy(local);
+	fs_candidate_destroy(remote);
 }
 
 static void
@@ -1077,10 +1119,8 @@ purple_media_add_stream_internal(PurpleM
 
 			param[0].name = "stun-ip";
 			g_value_init(&param[0].value, G_TYPE_STRING);
-			g_value_set_string(&param[0].value, stun_ip);
+			g_value_take_string(&param[0].value, stun_ip);
 
-			g_free(stun_ip);
-
 			param[1].name = "stun-timeout";
 			g_value_init(&param[1].value, G_TYPE_UINT);
 			g_value_set_uint(&param[1].value, 5);
@@ -1088,6 +1128,7 @@ purple_media_add_stream_internal(PurpleM
 			stream = fs_session_new_stream(session->session,
 					participant, type_direction,
 					transmitter, 2, param, &err);
+			g_free(stun_ip);
 		} else {
 			stream = fs_session_new_stream(session->session,
 					participant, type_direction,
@@ -1181,7 +1222,8 @@ purple_media_get_local_candidates(Purple
 purple_media_get_local_candidates(PurpleMedia *media, const gchar *sess_id, const gchar *name)
 {
 	PurpleMediaSession *session = purple_media_get_session(media, sess_id);
-	return purple_media_session_get_local_candidates(session, name);
+	return fs_candidate_list_copy(
+			purple_media_session_get_local_candidates(session, name));
 }
 
 GList *
============================================================
--- libpurple/protocols/jabber/jingle.c	494c5a27f19840f164f43ca76522b72553fca5e2
+++ libpurple/protocols/jabber/jingle.c	5d1a33c3a4d424e5ab6b512354f416aa25c7e942
@@ -253,6 +253,8 @@ jabber_jingle_session_destroy(JingleSess
 	GList *contents;
 	g_hash_table_remove(sess->js->sessions, sess->id);
 	g_free(sess->id);
+	g_free(sess->remote_jid);
+	g_free(sess->initiator);
 
 	if (sess->media)
 		g_object_unref(sess->media);
@@ -395,9 +397,11 @@ jabber_jingle_session_set_remote_jid(Jin
 
 static void
 jabber_jingle_session_set_remote_jid(JingleSession *sess, 
-									 const char *remote_jid)
+				     const char *remote_jid)
 {
-	sess->remote_jid = strdup(remote_jid);
+	if (sess->remote_jid)
+		g_free(sess->remote_jid);
+	sess->remote_jid = g_strdup(remote_jid);
 }
 
 static JingleSessionState
@@ -422,8 +426,10 @@ jabber_jingle_session_set_initiator(Jing
 
 static void
 jabber_jingle_session_set_initiator(JingleSession *sess,
-									const char *initiator)
+				    const char *initiator)
 {
+	if (sess->initiator)
+		g_free(sess->initiator);
 	sess->initiator = g_strdup(initiator);
 }
 
============================================================
--- pidgin/gtkconv.c	807134f4b8cedccc82bdaf57e1031a81517eacac
+++ pidgin/gtkconv.c	5ef285004e855ed16d71ad77fbdbedf8fb477088
@@ -7745,10 +7745,13 @@ pidgin_conv_new_media_cb(PurpleMediaMana
 	GtkWidget *gtkmedia;
 	PurpleConversation *conv;
 	PidginConversation *gtkconv;
+	gchar *name = purple_media_get_screenname(media);
 
 	conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,
-				       purple_connection_get_account(purple_media_get_connection(media)),
-				       purple_media_get_screenname(media));
+			purple_connection_get_account(
+			purple_media_get_connection(media)), name);
+	g_free(name);
+
 	gtkconv = PIDGIN_CONVERSATION(conv);
 
 	if (gtkconv->gtkmedia) {
============================================================
--- pidgin/gtkmedia.c	9356dc99c1eccdeb419fda3b1e66a084a60dd489
+++ pidgin/gtkmedia.c	4543a7684e0209c8083506313d6db55011afdc68
@@ -194,7 +194,7 @@ level_message_cb(GstBus *bus, GstMessage
 level_message_cb(GstBus *bus, GstMessage *message, PidginMedia *gtkmedia)
 {
 	const GstStructure *s;
-	const gchar *name;
+	gchar *name;
 
 	gdouble rms_db;
 	gdouble percent;
@@ -207,9 +207,8 @@ level_message_cb(GstBus *bus, GstMessage
 		return TRUE;
 
 	s = gst_message_get_structure(message);
-	name = gst_structure_get_name(s);
 
-	if (strcmp(name, "level"))
+	if (strcmp(gst_structure_get_name(s), "level"))
 		return TRUE;
 
 	list = gst_structure_get_value(s, "rms");
@@ -223,11 +222,13 @@ level_message_cb(GstBus *bus, GstMessage
 	if(percent > 1.0)
 		percent = 1.0;
 
-	if (!strcmp(gst_element_get_name(src), "sendlevel"))	
+	name = gst_element_get_name(src);
+	if (!strcmp(name, "sendlevel"))	
 		gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gtkmedia->priv->send_progress), percent);
 	else
 		gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gtkmedia->priv->recv_progress), percent);
 
+	g_free(name);
 	return TRUE;
 }
 
@@ -465,20 +466,23 @@ pidgin_media_got_request_cb(PurpleMedia 
 {
 	PurpleMediaSessionType type = purple_media_get_overall_type(media);
 	gchar *message;
+	gchar *name = purple_media_get_screenname(media);
 
 	if (type & PURPLE_MEDIA_AUDIO && type & PURPLE_MEDIA_VIDEO) {
 		message = g_strdup_printf(_("%s wishes to start an audio/video session with you."),
-					  purple_media_get_screenname(media));
+					  name);
 	} else if (type & PURPLE_MEDIA_AUDIO) {
 		message = g_strdup_printf(_("%s wishes to start an audio session with you."),
-					  purple_media_get_screenname(media));
+					  name);
 	} else if (type & PURPLE_MEDIA_VIDEO) {
 		message = g_strdup_printf(_("%s wishes to start a video session with you."),
-					  purple_media_get_screenname(media));
+					  name);
 	} else {
+		g_free(name);
 		return;
 	}
 
+	g_free(name);
 	pidgin_media_emit_message(gtkmedia, message);
 	g_free(message);
 }
============================================================
--- pidgin/gtkprefs.c	9333ae912802a8cc3efa4b18b8c78d37e00b91bc
+++ pidgin/gtkprefs.c	02bab9853d658ed9f2ed59f63d765175fd6dc666
@@ -2121,7 +2121,11 @@ media_plugin_changed_cb(const gchar *nam
 	if (video != NULL) {
 		GList *video_devices = purple_media_get_devices(video);
 		video_items = get_device_items(video, video_devices);
-		g_list_free(video_devices);
+		for(; video_devices; video_devices = g_list_delete_link(
+				video_devices, video_devices)) {
+			g_value_unset(video_devices->data);
+			g_free(video_devices->data);
+		}
 	}
 
 	if (video_items == NULL) {
@@ -2227,13 +2231,21 @@ media_page()
 	if (video != NULL) {
 		GList *video_devices = purple_media_get_devices(video);
 		video_items = get_device_items(video, video_devices);
-		g_list_free(video_devices);
+		for(; video_devices; video_devices = g_list_delete_link(
+				video_devices, video_devices)) {
+			g_value_unset(video_devices->data);
+			g_free(video_devices->data);
+		}
 	}
 
 	if (audio != NULL) {		
 		GList *audio_devices = purple_media_get_devices(audio);
 		audio_items = get_device_items(audio, audio_devices);
-		g_list_free(audio_devices);
+		for(; audio_devices; audio_devices = g_list_delete_link(
+				audio_devices, audio_devices)) {
+			g_value_unset(audio_devices->data);
+			g_free(audio_devices->data);
+		}
 	}
 
 	if (video_items == NULL) {


More information about the Commits mailing list