changeset 12:79f081cdfb19

- fixed potential memory leaks. - fixed indentation.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Sat, 27 Sep 2008 00:50:45 +0900
parents 43cb653de212
children 44568f7ef51d
files pidgin-audacious.c
diffstat 1 files changed, 71 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-audacious.c	Thu Sep 18 01:55:32 2008 +0900
+++ b/pidgin-audacious.c	Sat Sep 27 00:50:45 2008 +0900
@@ -1,4 +1,5 @@
-/*
+/* -*- indent-tabs-mode:t; tab-width:8; -*-
+ *
  * Pidgin-Audacious plugin.
  *
  * This program is free software; you can redistribute it and/or
@@ -68,7 +69,8 @@
 
 static void aud_process(gchar *aud_info);
 
-static DBusGProxy *get_dbus_proxy(void)
+static DBusGProxy *
+get_dbus_proxy(void)
 {
     DBusGConnection *connection = NULL;
     DBusGProxy *session = NULL;
@@ -148,12 +150,12 @@
 
     /* retrieve current user status */
 	current = purple_status_get_attr_string(status, "message");
-    aud_debug("status current = %s\n", current);
+	aud_debug("status current = %s\n", current);
 
     /* invalidate pushded status on auto away etc. */
 	if(current == NULL || strlen(current) == 0) {
 		g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(""));
-        g_free(key);
+		g_free(key);
         return;
     }
 
@@ -168,18 +170,25 @@
 
 	/* construct new status message */
 	seed = (gchar *)g_hash_table_lookup(seed_status, key);
-	g_return_if_fail(seed != NULL);
+	if(!seed) {
+		g_free(key);
+		return;
+	}
 	aud_debug("status seed = %s\n", seed);
 
-    if(strstr(seed, SONG_TOKEN)) {
-        if(aud_info){
-            new = purple_strreplace(seed, SONG_TOKEN, aud_info);
-        }
-        else {
-            new = g_strdup(NO_SONG_MESSAGE);
-        }
-    }
-	g_return_if_fail(new != NULL);
+	if(strstr(seed, SONG_TOKEN)) {
+		if(aud_info){
+			new = purple_strreplace(seed, SONG_TOKEN, aud_info);
+		}
+		else {
+			new = g_strdup(NO_SONG_MESSAGE);
+		}
+	}
+
+	if(!new) {
+		g_free(key);
+		return;
+	}
 
 	/* set status message only if text has been changed */
 	pushed = (gchar *)g_hash_table_lookup(pushed_status, key);
@@ -218,38 +227,45 @@
 
 	/* retrieve current user info */
 	current = purple_account_get_user_info(account);		/* it's always from account.xml! */
-    aud_debug("userinfo current = %s\n", current);
+	aud_debug("userinfo current = %s\n", current);
 
-    /* invalidate pushded status on auto away etc. */
+	/* invalidate pushded status on auto away etc. */
 	if(current == NULL || strlen(current) == 0) {
 		g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(""));
-        g_free(key);
-        return;
-    }
+		g_free(key);
+		return;
+	}
 
-    /* pop pushed_userinfo */
-    pushed = g_hash_table_lookup(pushed_userinfo, key);
+	/* pop pushed_userinfo */
+	pushed = g_hash_table_lookup(pushed_userinfo, key);
 
-    /* if current alias differs from pushed_alias or contains token, replace seed with this. */
-    if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) {
+	/* if current alias differs from pushed_alias or contains token, replace seed with this. */
+	if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) {
 		g_hash_table_replace(seed_userinfo, g_strdup(key), g_strdup(current));
 		g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(current));
-    }
+	}
 
 	/* construct new status message */
 	seed = (gchar *)g_hash_table_lookup(seed_userinfo, key);
-	g_return_if_fail(seed != NULL);
+	if(!seed) {
+		g_free(key);
+		return;
+	}
 	aud_debug("userinfo seed = %s\n", seed);
 
-    if(strstr(seed, SONG_TOKEN)) {
-        if(aud_info){
-            new = purple_strreplace(seed, SONG_TOKEN, aud_info);
-        }
-        else {
-            new = g_strdup(NO_SONG_MESSAGE);
-        }
-    }
-	g_return_if_fail(new != NULL);
+	if(strstr(seed, SONG_TOKEN)) {
+		if(aud_info){
+			new = purple_strreplace(seed, SONG_TOKEN, aud_info);
+		}
+		else {
+			new = g_strdup(NO_SONG_MESSAGE);
+		}
+	}
+
+	if(!new) {
+		g_free(key);
+		return;
+	}
 
 	/* set user info only if text has been changed */
 	pushed = (gchar *)g_hash_table_lookup(pushed_userinfo, key);
@@ -290,27 +306,30 @@
 	current = purple_account_get_alias(account);
 	if(current == NULL || strlen(current) == 0) {
 		aud_error("couldn't get current alias\n");
-        g_free(key);
+		g_free(key);
 		return;
 	}
 	aud_debug("current alias = %s\n", current);
 
-    /* pop pushed_alias */
-    pushed = g_hash_table_lookup(pushed_alias, key);
+	/* pop pushed_alias */
+	pushed = g_hash_table_lookup(pushed_alias, key);
 
-    /* if current alias differs from pushed_alias or contains token, replace seed with current. */
-    if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) {
+	/* if current alias differs from pushed_alias or contains token, replace seed with current. */
+	if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) {
 		g_hash_table_replace(seed_alias, g_strdup(key), g_strdup(current));
-    }
+	}
 
 	/* construct new status message */
 	seed = g_hash_table_lookup(seed_alias, key);
-	g_return_if_fail(seed != NULL);
+	if(!seed) {
+		g_free(key);
+		return;
+	}
 	aud_debug("alias: seed = %s\n", (gchar *)seed);
 
-    bytes = strlen(seed);
-    bytes -= strlen(SONG_TOKEN);
-    aud_debug("alias: bytes = %ld", bytes);
+	bytes = strlen(seed);
+	bytes -= strlen(SONG_TOKEN);
+	aud_debug("alias: bytes = %ld", bytes);
 
 	if(aud_info){
         gchar *tmp = g_malloc0(BUDDY_ALIAS_MAXLEN);
@@ -322,7 +341,10 @@
 	else {
 		new = purple_strreplace(seed, SONG_TOKEN, NO_SONG_MESSAGE);
 	}
-	g_return_if_fail(new != NULL);
+	if(!new) {
+		g_free(key);
+		return;
+	}
 
 	/* set user info only if text has been changed */
 	pushed = g_hash_table_lookup(pushed_alias, key);
@@ -394,7 +416,10 @@
 
 	key = g_strdup_printf("%s %s", account->username, account->protocol_id);
 	val = g_hash_table_lookup(seed_alias, key);
-	g_return_val_if_fail(val != NULL, FALSE);
+	if(!val) {
+		g_free(key);
+		return FALSE;
+	}
 
 	aud_debug("write back alias %s\n", (char *)val);
 	purple_account_set_alias(account, val); //oct16