changeset 22800:67a4c8c46f78

Cleanup allocations/frees to match and plug some leaks.
author Daniel Atallah <daniel.atallah@gmail.com>
date Sat, 03 May 2008 07:13:58 +0000
parents fc1e708ddf92
children 6fe3a32c5ee9
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
diffstat 7 files changed, 59 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/silc/buddy.c	Sat May 03 03:02:25 2008 +0000
+++ b/libpurple/protocols/silc/buddy.c	Sat May 03 07:13:58 2008 +0000
@@ -52,13 +52,13 @@
 			   _("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 @@
 	}
 
  out:
-	silc_free(a->hostname);
+	g_free(a->hostname);
 	silc_free(a);
 }
 
@@ -309,7 +309,7 @@
 	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(client->application, context);
-	silc_free(context);
+	g_free(context);
 }
 
 static void
@@ -544,7 +544,7 @@
 	}
 
 	silcpurple_buddy_getkey(client->application, context);
-	silc_free(context);
+	g_free(context);
 }
 
 static void
--- a/libpurple/protocols/silc/chat.c	Sat May 03 03:02:25 2008 +0000
+++ b/libpurple/protocols/silc/chat.c	Sat May 03 07:13:58 2008 +0000
@@ -92,7 +92,7 @@
 {
 	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 @@
 		}
 	}
 
-	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 @@
 
 	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 @@
 	silc_client_command_call(s->sg->client, s->sg->conn, NULL, "CMODE",
 				 s->channel, "+l", limit, NULL);
 
+	g_free(s->channel);
 	silc_free(s);
 }
 
--- a/libpurple/protocols/silc/ft.c	Sat May 03 03:02:25 2008 +0000
+++ b/libpurple/protocols/silc/ft.c	Sat May 03 07:13:58 2008 +0000
@@ -424,12 +424,12 @@
 			   (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 @@
 	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);
--- a/libpurple/protocols/silc/ops.c	Sat May 03 03:02:25 2008 +0000
+++ b/libpurple/protocols/silc/ops.c	Sat May 03 07:13:58 2008 +0000
@@ -462,7 +462,7 @@
 			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 @@
 		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 @@
 {
 	SilcAttributePayload attr;
 	SilcAttribute attribute;
-	char *buf;
 	GString *s;
 	SilcVCardStruct vcard;
 	int i;
@@ -1064,10 +1063,9 @@
 		}
 	}
 
-	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 @@
 			    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) {
--- a/libpurple/protocols/silc/pk.c	Sat May 03 03:02:25 2008 +0000
+++ b/libpurple/protocols/silc/pk.c	Sat May 03 07:13:58 2008 +0000
@@ -56,9 +56,9 @@
 					  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 @@
 		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 @@
 		/* 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);
--- a/libpurple/protocols/silc/silc.c	Sat May 03 03:02:25 2008 +0000
+++ b/libpurple/protocols/silc/silc.c	Sat May 03 07:13:58 2008 +0000
@@ -575,7 +575,7 @@
 
 	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 @@
 		                             _("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 @@
 	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 @@
 #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
 
 }
--- a/libpurple/protocols/silc/util.c	Sat May 03 03:02:25 2008 +0000
+++ b/libpurple/protocols/silc/util.c	Sat May 03 07:13:58 2008 +0000
@@ -338,7 +338,6 @@
 	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 @@
 	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 @@
 			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 @@
 			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 @@
 				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 @@
 	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 @@
 				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");