changeset 32764:cde7e464221b

Reorder create_stream() This eliminates a leak of _params when get_session() or get_participant() fails.
author Richard Laager <rlaager@wiktel.com>
date Wed, 04 Apr 2012 22:25:36 +0000
parents 88587257d083
children 60bd913072f7
files libpurple/media/backend-fs2.c
diffstat 1 files changed, 18 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/media/backend-fs2.c	Wed Apr 04 22:13:35 2012 +0000
+++ b/libpurple/media/backend-fs2.c	Wed Apr 04 22:25:36 2012 +0000
@@ -1767,7 +1767,7 @@
 	const gchar *stun_ip = purple_network_get_stun_ip();
 	const gchar *turn_ip = purple_network_get_turn_ip();
 	guint _num_params = num_params;
-	GParameter *_params = g_new0(GParameter, num_params + 3);
+	GParameter *_params;
 	FsStreamDirection type_direction =
 			session_type_to_fs_stream_direction(type);
 	PurpleMediaBackendFs2Session *session;
@@ -1779,6 +1779,22 @@
 	gboolean got_turn_from_prpl = FALSE;
 	int i;
 
+	session = get_session(self, sess_id);
+
+	if (session == NULL) {
+		purple_debug_error("backend-fs2",
+				"Couldn't find session to create stream.\n");
+		return FALSE;
+	}
+
+	participant = get_participant(self, who);
+
+	if (participant == NULL) {
+		purple_debug_error("backend-fs2", "Couldn't find "
+				"participant to create stream.\n");
+		return FALSE;
+	}
+
 	for (i = 0 ; i < num_params ; i++) {
 		if (purple_strequal(params[i].name, "relay-info")) {
 			got_turn_from_prpl = TRUE;
@@ -1786,6 +1802,7 @@
 		}
 	}
 
+	_params = g_new0(GParameter, num_params + 3);
 	memcpy(_params, params, sizeof(GParameter) * num_params);
 
 	/* set the controlling mode parameter */
@@ -1840,22 +1857,6 @@
 		_num_params++;
 	}
 
-	session = get_session(self, sess_id);
-
-	if (session == NULL) {
-		purple_debug_error("backend-fs2",
-				"Couldn't find session to create stream.\n");
-		return FALSE;
-	}
-
-	participant = get_participant(self, who);
-
-	if (participant == NULL) {
-		purple_debug_error("backend-fs2", "Couldn't find "
-				"participant to create stream.\n");
-		return FALSE;
-	}
-
 	fsstream = fs_session_new_stream(session->session, participant,
 			initiator == TRUE ? type_direction :
 			(type_direction & FS_DIRECTION_RECV), transmitter,