Mercurial > pidgin
diff libpurple/protocols/myspace/user.c @ 20753:61045691aa72
Fix a few more memory leaks. Someone who has a myspace account should stare
at the code and fix leaks.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Tue, 02 Oct 2007 06:13:27 +0000 |
parents | c43a36cb31a6 |
children | aee8d876fed1 |
line wrap: on
line diff
--- a/libpurple/protocols/myspace/user.c Tue Oct 02 04:38:10 2007 +0000 +++ b/libpurple/protocols/myspace/user.c Tue Oct 02 06:13:27 2007 +0000 @@ -30,10 +30,10 @@ static gchar * msim_format_now_playing(gchar *band, gchar *song) { - if ((band && strlen(band)) || (song && strlen(song))) { + if ((band && *band) || (song && *song)) { return g_strdup_printf("%s - %s", - (band && strlen(band)) ? band : "Unknown Artist", - (song && strlen(song)) ? song : "Unknown Song"); + (band && *band) ? band : "Unknown Artist", + (song && *song) ? song : "Unknown Song"); } else { return NULL; } @@ -99,58 +99,63 @@ if (full) { /* TODO: link to username, if available */ - purple_notify_user_info_add_pair(user_info, _("Profile"), - g_strdup_printf("<a href=\"http://myspace.com/%d\">http://myspace.com/%d</a>", - uid, uid)); + char *profile = g_strdup_printf("<a href=\"http://myspace.com/%d\">http://myspace.com/%d</a>", + uid, uid); + purple_notify_user_info_add_pair(user_info, _("Profile"), profile); + g_free(profile); } /* a/s/l...the vitals */ if (user->age) { - purple_notify_user_info_add_pair(user_info, _("Age"), - g_strdup_printf("%d", user->age)); + char age[16]; + g_snprintf(age, sizeof(age), "%d", user->age); + purple_notify_user_info_add_pair(user_info, _("Age"), age); } - if (user->gender && strlen(user->gender)) { + if (user->gender && *user->gender) { purple_notify_user_info_add_pair(user_info, _("Gender"), user->gender); } - if (user->location && strlen(user->location)) { + if (user->location && *user->location) { purple_notify_user_info_add_pair(user_info, _("Location"), user->location); } /* Other information */ - if (user->headline && strlen(user->headline)) { + if (user->headline && *user->headline) { purple_notify_user_info_add_pair(user_info, _("Headline"), user->headline); } str = msim_format_now_playing(user->band_name, user->song_name); - if (str && strlen(str)) { + if (str && *str) { purple_notify_user_info_add_pair(user_info, _("Song"), str); } + g_free(str); /* Note: total friends only available if looked up by uid, not username. */ if (user->total_friends) { - purple_notify_user_info_add_pair(user_info, _("Total Friends"), - g_strdup_printf("%d", user->total_friends)); + char friends[16]; + g_snprintf(friends, sizeof(friends), "%d", user->total_friends); + purple_notify_user_info_add_pair(user_info, _("Total Friends"), friends); } if (full) { /* Client information */ + char *client = NULL; str = user->client_info; cv = user->client_cv; if (str && cv != 0) { - purple_notify_user_info_add_pair(user_info, _("Client Version"), - g_strdup_printf("%s (build %d)", str, cv)); + client = g_strdup_printf("%s (build %d)", str, cv); } else if (str) { - purple_notify_user_info_add_pair(user_info, _("Client Version"), - g_strdup(str)); + client = g_strdup(str); } else if (cv) { - purple_notify_user_info_add_pair(user_info, _("Client Version"), - g_strdup_printf("Build %d", cv)); + client = g_strdup_printf("Build %d", cv); } + if (client && *client) + purple_notify_user_info_add_pair(user_info, _("Client Version"), client); + g_free(client); } }