pidgin: 2aab3939: Leak fixes. Avoid creating an unnecessar...
datallah at pidgin.im
datallah at pidgin.im
Sat May 3 19:56:38 EDT 2008
-----------------------------------------------------------------
Revision: 2aab3939318b7e131386caf77cf2641f6b0b3e0f
Ancestor: 48c9785414ebedaa4c514a00bb5fa17504252675
Author: datallah at pidgin.im
Date: 2008-05-03T21:03:13
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/2aab3939318b7e131386caf77cf2641f6b0b3e0f
Modified files:
libpurple/protocols/yahoo/yahoo.c
libpurple/protocols/yahoo/yahoo_aliases.c
libpurple/protocols/yahoo/yahoo_aliases.h
libpurple/protocols/yahoo/yahoo_friend.c
libpurple/protocols/yahoo/yahoo_friend.h
ChangeLog:
Leak fixes. Avoid creating an unnecessary parallel data structure to YahooFriend.
-------------- next part --------------
============================================================
--- libpurple/protocols/yahoo/yahoo.c fbe9dedb1b8e662339c47ad83de8b2df9d4bdb4b
+++ libpurple/protocols/yahoo/yahoo.c 23fa3848b37595311c16d91f18d2fd5c6308af36
@@ -3483,9 +3483,12 @@ yahoo_get_inbox_token_cb(PurpleUtilFetch
{
PurpleConnection *gc = user_data;
gboolean set_cookie = FALSE;
- char *url;
+ gchar *url;
+ struct yahoo_data *yd = gc->proto_data;
g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc));
+
+ yd->url_datas = g_slist_remove(yd->url_datas, url_data);
if (error_message != NULL)
purple_debug_error("yahoo", "Requesting mail login token failed: %s\n", error_message);
@@ -3500,7 +3503,6 @@ yahoo_get_inbox_token_cb(PurpleUtilFetch
}
if (!set_cookie) {
- struct yahoo_data *yd = gc->proto_data;
purple_debug_error("yahoo", "No mail login token; forwarding to login screen.\n");
url = g_strdup(yd->jp ? YAHOOJP_MAIL_URL : YAHOO_MAIL_URL);
}
@@ -3541,7 +3543,9 @@ static void yahoo_show_inbox(PurplePlugi
g_free(request);
- if (url_data == NULL) {
+ if (url_data != NULL)
+ yd->url_datas = g_slist_prepend(yd->url_datas, url_data);
+ else {
const char *yahoo_mail_url = (yd->jp ? YAHOOJP_MAIL_URL : YAHOO_MAIL_URL);
purple_debug_error("yahoo",
"Unable to request mail login token; forwarding to login screen.");
============================================================
--- libpurple/protocols/yahoo/yahoo_aliases.c 40d761acaf7a13a6ec8bc51f59af138843713e31
+++ libpurple/protocols/yahoo/yahoo_aliases.c b506c9a20ff69dd02e6dcd6b5c185522d467ddda
@@ -32,6 +32,7 @@
#include "version.h"
#include "yahoo.h"
#include "yahoo_aliases.h"
+#include "yahoo_friend.h"
#include "yahoo_packet.h"
/* I hate hardcoding this stuff, but Yahoo never sends us anything to use. Someone in the know may be able to tweak this URL */
@@ -70,7 +71,8 @@ yahoo_fetch_aliases_cb(PurpleUtilFetchUr
} else {
gchar *full_name, *nick_name, *alias;
const char *yid, *id, *fn, *ln, *nn;
- PurpleBuddy *b = NULL;
+ YahooFriend *f;
+ PurpleBuddy *b;
xmlnode *item, *contacts;
/* Put our web response into a xmlnode for easy management */
@@ -108,19 +110,12 @@ yahoo_fetch_aliases_cb(PurpleUtilFetchUr
alias = full_name; /* If no Yahoo nickname, we can use the full_name created above */
/* Find the local buddy that matches */
+ f = yahoo_friend_find(cb->gc, yid);
b = purple_find_buddy(cb->gc->account, yid);
/* If we don't find a matching buddy, ignore the alias !! */
- if (b != NULL) {
- /* Create an object that we can attach to the buddies proto_data pointer */
- struct YahooUser *yu;
- yu = g_new0(struct YahooUser, 1);
- yu->id = g_strdup(id);
- yu->firstname = g_strdup(fn);
- yu->lastname = g_strdup(ln);
- yu->nickname = g_strdup(nn);
- /* TODO: Isn't there a possiblity that b->proto_data is already set? */
- b->proto_data=yu;
+ if (f != NULL && b != NULL) {
+ yahoo_friend_set_alias_id(f, id);
/* Finally, if we received an alias, we better update the buddy list */
if (alias != NULL) {
@@ -237,14 +232,13 @@ yahoo_update_alias(PurpleConnection *gc,
yahoo_update_alias(PurpleConnection *gc, const char *who, const char *alias)
{
struct yahoo_data *yd;
- struct YahooUser *yu;
char *content, *url, *request, *webpage, *webaddress, *strtmp;
char *escaped_alias, *alias_jp, *converted_alias_jp;
int inttmp;
struct callback_data *cb;
- PurpleBuddy *buddy;
PurpleUtilFetchUrlData *url_data;
gboolean use_whole_url = FALSE;
+ YahooFriend *f;
/* use whole URL if using HTTP Proxy */
if ((gc->account->proxy_info) && (gc->account->proxy_info->type == PURPLE_PROXY_HTTP))
@@ -254,20 +248,19 @@ yahoo_update_alias(PurpleConnection *gc,
g_return_if_fail(who != NULL);
g_return_if_fail(gc != NULL);
- purple_debug_info("yahoo", "Sending '%s' as new alias for user '%s'.\n",alias, who);
+ purple_debug_info("yahoo", "Sending '%s' as new alias for user '%s'.\n", alias, who);
- buddy = purple_find_buddy(gc->account, who);
- if (buddy == NULL || buddy->proto_data == NULL) {
+ f = yahoo_friend_find(gc, who);
+ if (f == NULL) {
purple_debug_info("yahoo", "Missing proto_data (get_yahoo_aliases must have failed), bailing out\n");
return;
}
yd = gc->proto_data;
- yu = buddy->proto_data;
/* Using callback_data so I have access to gc in the callback function */
cb = g_new0(struct callback_data, 1);
- cb->id = g_strdup(yu->id);
+ cb->id = g_strdup(yahoo_friend_get_alias_id(f));
cb->gc = gc;
/* Build all the info to make the web request */
@@ -279,7 +272,7 @@ yahoo_update_alias(PurpleConnection *gc,
converted_alias_jp = yahoo_convert_to_numeric(alias_jp);
content = g_strdup_printf("<ab k=\"%s\" cc=\"1\">\n"
"<ct e=\"1\" yi='%s' id='%s' nn='%s' pr='0' />\n</ab>\r\n",
- gc->account->username, who, yu->id, converted_alias_jp);
+ gc->account->username, who, yahoo_friend_get_alias_id(f), converted_alias_jp);
free(converted_alias_jp);
g_free(alias_jp);
}
@@ -287,7 +280,7 @@ yahoo_update_alias(PurpleConnection *gc,
escaped_alias = g_markup_escape_text(alias, strlen(alias));
content = g_strdup_printf("<?xml version=\"1.0\" encoding=\"utf-8\"?><ab k=\"%s\" cc=\"1\">\n"
"<ct e=\"1\" yi='%s' id='%s' nn='%s' pr='0' />\n</ab>\r\n",
- gc->account->username, who, yu->id, escaped_alias);
+ gc->account->username, who, yahoo_friend_get_alias_id(f), escaped_alias);
g_free(escaped_alias);
}
============================================================
--- libpurple/protocols/yahoo/yahoo_aliases.h 3593fe557f164f39349b6afea702f0e691008068
+++ libpurple/protocols/yahoo/yahoo_aliases.h cb68f757e203f5f224e5d49484d9f7e77d00497c
@@ -33,18 +33,6 @@
#include "yahoo.h"
#include "yahoo_packet.h"
-
-/**
- * The additional protocol specific info attached to each buddy. We need
- * to store the unique numeric id number to allow us to push alias changes.
- */
-struct YahooUser
-{
- const char *id; /* The yahoo accountid for this buddy (not YahooID but numeric value) */
- char *firstname; /* Storing this information for no real reason, just because */
- char *lastname; /* Storing this information for no real reason, just because */
- char *nickname; /* Storing this information for no real reason, just because */
-};
-
void yahoo_update_alias(PurpleConnection *gc, const char *who, const char *alias);
void yahoo_fetch_aliases(PurpleConnection *gc);
+
============================================================
--- libpurple/protocols/yahoo/yahoo_friend.c d2fa02e486c9cf3033c3860faa81ad977a391fc8
+++ libpurple/protocols/yahoo/yahoo_friend.c c72b3949de0d01926b740dd8707a99f3381bf480
@@ -76,8 +76,7 @@ void yahoo_friend_set_ip(YahooFriend *f,
void yahoo_friend_set_ip(YahooFriend *f, const char *ip)
{
- if (f->ip)
- g_free(f->ip);
+ g_free(f->ip);
f->ip = g_strdup(ip);
}
@@ -88,8 +87,7 @@ void yahoo_friend_set_game(YahooFriend *
void yahoo_friend_set_game(YahooFriend *f, const char *game)
{
- if (f->game)
- g_free(f->game);
+ g_free(f->game);
if (game)
f->game = g_strdup(game);
@@ -104,8 +102,7 @@ void yahoo_friend_set_status_message(Yah
void yahoo_friend_set_status_message(YahooFriend *f, char *msg)
{
- if (f->msg)
- g_free(f->msg);
+ g_free(f->msg);
f->msg = msg;
}
@@ -125,15 +122,24 @@ gboolean yahoo_friend_get_buddy_icon_nee
return !f->bicon_sent_request;
}
+void yahoo_friend_set_alias_id(YahooFriend *f, const char *alias_id)
+{
+ g_free(f->alias_id);
+ f->alias_id = g_strdup(alias_id);
+}
+
+const char *yahoo_friend_get_alias_id(YahooFriend *f)
+{
+ return f->alias_id;
+}
+
void yahoo_friend_free(gpointer p)
{
YahooFriend *f = p;
- if (f->msg)
- g_free(f->msg);
- if (f->game)
- g_free(f->game);
- if (f->ip)
- g_free(f->ip);
+ g_free(f->msg);
+ g_free(f->game);
+ g_free(f->ip);
+ g_free(f->alias_id);
g_free(f);
}
============================================================
--- libpurple/protocols/yahoo/yahoo_friend.h f988f550ec8f4cd840e94b584c400d515a876ee9
+++ libpurple/protocols/yahoo/yahoo_friend.h 6057e470a8d36c004f4dad4f19bfcd4b10cb578a
@@ -39,16 +39,17 @@ typedef struct _YahooFriend {
*/
typedef struct _YahooFriend {
enum yahoo_status status;
- char *msg;
- char *game;
+ gchar *msg;
+ gchar *game;
int idle;
int away;
gboolean sms;
- char *ip;
+ gchar *ip;
gboolean bicon_sent_request;
YahooPresenceVisibility presence;
int protocol; /* 1=LCS, 2=MSN*/
long int version_id;
+ gchar *alias_id;
} YahooFriend;
YahooFriend *yahoo_friend_find(PurpleConnection *gc, const char *name);
@@ -63,6 +64,9 @@ const char *yahoo_friend_get_status_mess
void yahoo_friend_set_status_message(YahooFriend *f, char *msg);
const char *yahoo_friend_get_status_message(YahooFriend *f);
+void yahoo_friend_set_alias_id(YahooFriend *f, const char *alias_id);
+const char *yahoo_friend_get_alias_id(YahooFriend *f);
+
void yahoo_friend_set_buddy_icon_need_request(YahooFriend *f, gboolean needs);
gboolean yahoo_friend_get_buddy_icon_need_request(YahooFriend *f);
More information about the Commits
mailing list