pidgin: f9260bd4: Cleanup allocations/frees to match and p..

datallah at pidgin.im datallah at pidgin.im
Sat May 3 03:15:49 EDT 2008


-----------------------------------------------------------------
Revision: f9260bd456d14b2e90b3b5c1a778f953d7058bba
Ancestor: 3ee7b50a104560d579c7c5de785bea5675d135b3
Author: datallah at pidgin.im
Date: 2008-05-03T07:13:58
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/f9260bd456d14b2e90b3b5c1a778f953d7058bba

Modified files:
        libpurple/protocols/silc/buddy.c
        libpurple/protocols/silc/chat.c
        libpurple/protocols/silc/ft.c libpurple/protocols/silc/ops.c
        libpurple/protocols/silc/pk.c
        libpurple/protocols/silc/silc.c
        libpurple/protocols/silc/util.c

ChangeLog: 

Cleanup allocations/frees to match and plug some leaks.

-------------- next part --------------
============================================================
--- libpurple/protocols/silc/buddy.c	64cd6b56d67dab2995b54587f6ecb605fb431a55
+++ libpurple/protocols/silc/buddy.c	9ae58b26db01e069dcd7ebe489e4aae653ba7847
@@ -52,13 +52,13 @@ silcpurple_buddy_keyagr_resolved(SilcCli
 			   _("User %s is not present in the network"), r->nick);
 		purple_notify_error(gc, _("Key Agreement"),
 				  _("Cannot perform the key agreement"), tmp);
-		silc_free(r->nick);
+		g_free(r->nick);
 		silc_free(r);
 		return;
 	}
 
 	silcpurple_buddy_keyagr_do(gc, r->nick, FALSE);
-	silc_free(r->nick);
+	g_free(r->nick);
 	silc_free(r);
 }
 
@@ -276,7 +276,7 @@ silcpurple_buddy_keyagr_request_cb(SilcP
 	}
 
  out:
-	silc_free(a->hostname);
+	g_free(a->hostname);
 	silc_free(a);
 }
 
@@ -309,7 +309,7 @@ void silcpurple_buddy_keyagr_request(Sil
 	a->conn = conn;
 	a->client_id = client_entry->id;
 	if (hostname)
-		a->hostname = strdup(hostname);
+		a->hostname = g_strdup(hostname);
 	a->port = port;
 
 	purple_request_action(client->application, _("Key Agreement Request"), tmp,
@@ -416,7 +416,7 @@ silcpurple_buddy_privkey_resolved(SilcCl
 	}
 
 	silcpurple_buddy_privkey(client->application, context);
-	silc_free(context);
+	g_free(context);
 }
 
 static void
@@ -544,7 +544,7 @@ silcpurple_buddy_getkey_resolved(SilcCli
 	}
 
 	silcpurple_buddy_getkey(client->application, context);
-	silc_free(context);
+	g_free(context);
 }
 
 static void
============================================================
--- libpurple/protocols/silc/chat.c	0146868e917dfab3a6b6792ae57b00381ef8a94e
+++ libpurple/protocols/silc/chat.c	269087fd5bb3485c0892cb95938c0a34e40314af
@@ -92,7 +92,7 @@ silcpurple_chat_getinfo(PurpleConnection
 {
 	SilcPurple sg = gc->proto_data;
 	const char *chname;
-	char *buf, tmp[256], *tmp2;
+	char tmp[256], *tmp2;
 	GString *s;
 	SilcChannelEntry channel;
 	SilcHashTableList htl;
@@ -173,9 +173,8 @@ silcpurple_chat_getinfo(PurpleConnection
 		}
 	}
 
-	buf = g_string_free(s, FALSE);
-	purple_notify_formatted(gc, NULL, _("Channel Information"), NULL, buf, NULL, NULL);
-	g_free(buf);
+	purple_notify_formatted(gc, NULL, _("Channel Information"), NULL, s->str, NULL, NULL);
+	g_string_free(s, TRUE);
 }
 
 
@@ -689,17 +688,20 @@ silcpurple_chat_ulimit_cb(SilcPurpleChat
 
 	if (!limit || !(*limit) || *limit == '0') {
 		if (limit && ulimit == channel->user_limit) {
+			g_free(s->channel);
 			silc_free(s);
 			return;
 		}
 		silc_client_command_call(s->sg->client, s->sg->conn, NULL, "CMODE",
 					 s->channel, "-l", NULL);
 
+		g_free(s->channel);
 		silc_free(s);
 		return;
 	}
 
 	if (ulimit == channel->user_limit) {
+		g_free(s->channel);
 		silc_free(s);
 		return;
 	}
@@ -708,6 +710,7 @@ silcpurple_chat_ulimit_cb(SilcPurpleChat
 	silc_client_command_call(s->sg->client, s->sg->conn, NULL, "CMODE",
 				 s->channel, "+l", limit, NULL);
 
+	g_free(s->channel);
 	silc_free(s);
 }
 
============================================================
--- libpurple/protocols/silc/ft.c	b36bcbd1f726e2c0906f62d8975b8a0299874302
+++ libpurple/protocols/silc/ft.c	8453accf89e77babc98477f9c0ec6e55e926b801
@@ -424,12 +424,12 @@ silcpurple_ftp_send_file_resolved(SilcCl
 			   (const char *)context);
 		purple_notify_error(gc, _("Secure File Transfer"),
 				  _("Cannot send file"), tmp);
-		silc_free(context);
+		g_free(context);
 		return;
 	}
 
 	silcpurple_ftp_send_file(client->application, (const char *)context, NULL);
-	silc_free(context);
+	g_free(context);
 }
 
 PurpleXfer *silcpurple_ftp_new_xfer(PurpleConnection *gc, const char *name)
@@ -447,7 +447,7 @@ PurpleXfer *silcpurple_ftp_new_xfer(Purp
 	if (!clients) {
 		silc_client_get_clients(client, conn, name, NULL,
 					silcpurple_ftp_send_file_resolved,
-					strdup(name));
+					g_strdup(name));
 		return NULL;
 	}
 	silc_dlist_start(clients);
============================================================
--- libpurple/protocols/silc/ops.c	05743b25b6be1403d174dee4e493261536a12f09
+++ libpurple/protocols/silc/ops.c	d9a4fa0109e743e1cf244a4f0f849e50433876d9
@@ -462,7 +462,7 @@ silc_notify(SilcClient client, SilcClien
 			client_entry = va_arg(va, SilcClientEntry);
 
 			components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
-			g_hash_table_insert(components, strdup("channel"), strdup(name));
+			g_hash_table_insert(components, g_strdup("channel"), g_strdup(name));
 			serv_got_chat_invite(gc, name, client_entry->nickname, NULL, components);
 		}
 		break;
@@ -484,7 +484,7 @@ silc_notify(SilcClient client, SilcClien
 		g_snprintf(buf, sizeof(buf), "%s@%s",
 			   client_entry->username, client_entry->hostname);
 		purple_conv_chat_add_user(PURPLE_CONV_CHAT(convo),
-					  g_strdup(client_entry->nickname), buf, PURPLE_CBFLAGS_NONE, TRUE);
+					  client_entry->nickname, buf, PURPLE_CBFLAGS_NONE, TRUE);
 
 		break;
 
@@ -974,7 +974,6 @@ silcpurple_whois_more(SilcClientEntry cl
 {
 	SilcAttributePayload attr;
 	SilcAttribute attribute;
-	char *buf;
 	GString *s;
 	SilcVCardStruct vcard;
 	int i;
@@ -1064,10 +1063,9 @@ silcpurple_whois_more(SilcClientEntry cl
 		}
 	}
 
-	buf = g_string_free(s, FALSE);
 	purple_notify_info(NULL, _("User Information"), _("User Information"),
-			 buf);
-	g_free(buf);
+			 s->str);
+	g_string_free(s, TRUE);
 }
 #endif
 
@@ -1133,7 +1131,7 @@ silc_command_reply(SilcClient client, Si
 			    f |= PURPLE_CBFLAGS_FOUNDER;
 			  if (chu->mode & SILC_CHANNEL_UMODE_CHANOP)
 			    f |= PURPLE_CBFLAGS_OP;
-			  users = g_list_append(users, g_strdup(chu->client->nickname));
+			  users = g_list_append(users, chu->client->nickname);
 			  flags = g_list_append(flags, GINT_TO_POINTER(f));
 
 			  if (chu->mode & SILC_CHANNEL_UMODE_CHANFO) {
============================================================
--- libpurple/protocols/silc/pk.c	d51e1c49b31e88f5a0d34afb6f4cc4b0170c9eb2
+++ libpurple/protocols/silc/pk.c	00efb4b50b54c290d371f1ae587578e6a09686ab
@@ -56,9 +56,9 @@ static void silcpurple_verify_cb(PublicK
 					  SILC_PKCS_FILE_BASE64);
 	}
 
-	silc_free(verify->filename);
-	silc_free(verify->entity);
-	silc_free(verify->entity_name);
+	g_free(verify->filename);
+	g_free(verify->entity);
+	g_free(verify->entity_name);
 	silc_free(verify->fingerprint);
 	silc_free(verify->babbleprint);
 	silc_pkcs_public_key_free(verify->public_key);
@@ -211,10 +211,10 @@ void silcpurple_verify_public_key(SilcCl
 		return;
 	verify->client = client;
 	verify->conn = conn;
-	verify->filename = strdup(ipf);
-	verify->entity = strdup(entity);
+	verify->filename = g_strdup(ipf);
+	verify->entity = g_strdup(entity);
 	verify->entity_name = (conn_type != SILC_CONN_CLIENT ?
-			       (name ? strdup(name) : strdup(hostname))
+			       (name ? g_strdup(name) : g_strdup(hostname))
 			       : NULL);
 	verify->public_key = silc_pkcs_public_key_copy(public_key);
 	verify->completion = completion;
@@ -262,9 +262,9 @@ void silcpurple_verify_public_key(SilcCl
 		/* Local copy matched */
 		if (completion)
 			completion(TRUE, context);
-		silc_free(verify->filename);
-		silc_free(verify->entity);
-		silc_free(verify->entity_name);
+		g_free(verify->filename);
+		g_free(verify->entity);
+		g_free(verify->entity_name);
 		silc_free(verify->fingerprint);
 		silc_free(verify->babbleprint);
 		silc_pkcs_public_key_free(verify->public_key);
============================================================
--- libpurple/protocols/silc/silc.c	c659c8776178b6d9861c147bd29017d1484161d9
+++ libpurple/protocols/silc/silc.c	0ac6cacae9f8fd90db1911893541a03139bffbf8
@@ -575,7 +575,7 @@ silcpurple_login(PurpleAccount *account)
 
 	username = (char *)purple_account_get_username(account);
 	up = g_strsplit(username, "@", 2);
-	username = strdup(up[0]);
+	username = g_strdup(up[0]);
 	g_strfreev(up);
 
 	if (!purple_account_get_user_info(account)) {
@@ -619,12 +619,12 @@ silcpurple_login(PurpleAccount *account)
 		                             _("Cannot initialize SILC protocol"));
 		gc->proto_data = NULL;
 		silc_free(sg);
-		free(hostname);
-		free(username);
+		silc_free(hostname);
+		g_free(username);
 		return;
 	}
-	free(hostname);
-	free(username);
+	silc_free(hostname);
+	g_free(username);
 
 	/* Check the ~/.silc dir and create it, and new key pair if necessary. */
 	if (!silcpurple_check_silc_dir(gc)) {
@@ -2111,6 +2111,15 @@ static PurplePluginInfo info =
 	NULL
 };
 
+#if 0
+static SilcBool silcpurple_debug_cb(char *file, char *function, int line,
+		char *message, void *context)
+{
+	purple_debug_info("SILC", "%s:%d:%s - %s\n", file ? file : "(null)", line, function ? function : "(null)", message ? message : "(null)");
+	return TRUE;
+}
+#endif
+
 static void
 init_plugin(PurplePlugin *plugin)
 {
@@ -2189,6 +2198,8 @@ silc_log_set_debug_string("*client*");
 #if 0
 silc_log_debug(TRUE);
 silc_log_set_debug_string("*client*");
+silc_log_quick(TRUE);
+silc_log_set_debug_callbacks(silcpurple_debug_cb, NULL, NULL, NULL);
 #endif
 
 }
============================================================
--- libpurple/protocols/silc/util.c	39d4c4b22ea5b41e7a18205370089578a759bb16
+++ libpurple/protocols/silc/util.c	3ccdc185e76ec192f230a586c4b19b18b05bc0f4
@@ -338,7 +338,6 @@ void silcpurple_show_public_key(SilcPurp
 	unsigned char *pk;
 	SilcUInt32 pk_len, key_len = 0;
 	GString *s;
-	char *buf;
 
 	/* We support showing only SILC public keys for now */
 	if (silc_pkcs_get_type(public_key) != SILC_PKCS_SILC)
@@ -380,14 +379,12 @@ void silcpurple_show_public_key(SilcPurp
 	g_string_append_printf(s, _("Public Key Fingerprint:\n%s\n\n"), fingerprint);
 	g_string_append_printf(s, _("Public Key Babbleprint:\n%s"), babbleprint);
 
-	buf = g_string_free(s, FALSE);
-
 	purple_request_action(sg->gc, _("Public Key Information"),
 			      _("Public Key Information"),
-			      buf, 0, purple_connection_get_account(sg->gc),
+			      s->str, 0, purple_connection_get_account(sg->gc),
 			      NULL, NULL, context, 1, _("Close"), callback);
 
-	g_free(buf);
+	g_string_free(s, TRUE);
 	silc_free(fingerprint);
 	silc_free(babbleprint);
 	silc_free(pk);
@@ -545,8 +542,7 @@ silcpurple_parse_attrs(SilcDList attrs, 
 			g_string_append_printf(s, "[%s] ", _("Anxious"));
 	}
 	if (strlen(s->str)) {
-		*moodstr = s->str;
-		g_string_free(s, FALSE);
+		*moodstr = g_string_free(s, FALSE);
 		g_strchomp(*moodstr);
 	} else
 		g_string_free(s, TRUE);
@@ -575,8 +571,7 @@ silcpurple_parse_attrs(SilcDList attrs, 
 			g_string_append_printf(s, "[%s] ", _("Video Conferencing"));
 	}
 	if (strlen(s->str)) {
-		*contactstr = s->str;
-		g_string_free(s, FALSE);
+		*contactstr = g_string_free(s, FALSE);
 		g_strchomp(*contactstr);
 	} else
 		g_string_free(s, TRUE);
@@ -604,10 +599,9 @@ silcpurple_parse_attrs(SilcDList attrs, 
 				device.model ? device.model : "",
 				device.language ? device.language : "");
 	}
-	if (strlen(s->str)) {
-		*devicestr = s->str;
-		g_string_free(s, FALSE);
-	} else
+	if (strlen(s->str))
+		*devicestr = g_string_free(s, FALSE);
+	else
 		g_string_free(s, TRUE);
 
 	attr = silcpurple_get_attr(attrs, SILC_ATTRIBUTE_TIMEZONE);
@@ -635,15 +629,15 @@ char *silcpurple_file2mime(const char *f
 	if (!ct)
 		return NULL;
 	else if (!g_ascii_strcasecmp(".png", ct))
-		return strdup("image/png");
+		return g_strdup("image/png");
 	else if (!g_ascii_strcasecmp(".jpg", ct))
-		return strdup("image/jpeg");
+		return g_strdup("image/jpeg");
 	else if (!g_ascii_strcasecmp(".jpeg", ct))
-		return strdup("image/jpeg");
+		return g_strdup("image/jpeg");
 	else if (!g_ascii_strcasecmp(".gif", ct))
-		return strdup("image/gif");
+		return g_strdup("image/gif");
 	else if (!g_ascii_strcasecmp(".tiff", ct))
-		return strdup("image/tiff");
+		return g_strdup("image/tiff");
 
 	return NULL;
 }
@@ -705,7 +699,7 @@ SilcDList silcpurple_image_message(const
 				continue;
 			}
 			silc_mime_add_field(p, "Content-Type", type);
-			silc_free(type);
+			g_free(type);
 
 			/* Add content transfer encoding */
 			silc_mime_add_field(p, "Content-Transfer-Encoding", "binary");


More information about the Commits mailing list