/pidgin/main: dc22f856e957: fix a memory leak (I've been in c++ ...

Nathan Walp nwalp at pidgin.im
Mon Sep 24 13:54:58 EDT 2012


Changeset: dc22f856e95734e9c8b248adfe98d96beeb53ae2
Author:	 Nathan Walp <nwalp at pidgin.im>
Date:	 2012-09-24 13:54 -0400
Branch:	 default
URL: http://hg.pidgin.im/pidgin/main/rev/dc22f856e957

Description:

fix a memory leak (I've been in c++ land too long)
adhere to the rule of thumb: if your boolean variable needs 2 lines of comments to explain, you named it badly

diffstat:

 libpurple/protocols/jabber/presence.c |  10 +++++-----
 libpurple/protocols/jabber/presence.h |   4 +---
 2 files changed, 6 insertions(+), 8 deletions(-)

diffs (58 lines):

diff --git a/libpurple/protocols/jabber/presence.c b/libpurple/protocols/jabber/presence.c
--- a/libpurple/protocols/jabber/presence.c
+++ b/libpurple/protocols/jabber/presence.c
@@ -1017,7 +1017,7 @@ void jabber_presence_parse(JabberStream 
 			pih(js, &presence, child);
 	}
 
-	if (presence.delayed && presence.idle && !presence.absolute_idle) {
+	if (presence.delayed && presence.idle && presence.adjust_idle_for_delay) {
 		/* Delayed and idle, so update idle time */
 		presence.idle = presence.idle + (time(NULL) - presence.sent);
 	}
@@ -1176,19 +1176,19 @@ parse_apple_idle(JabberStream *js, Jabbe
 {
 	xmlnode *since = xmlnode_get_child(x, "idle-since");
 	if (since) {
-		const char *stamp = xmlnode_get_data(since);
+		char *stamp = xmlnode_get_data_unescaped(since);
 		if (stamp) {
 			time_t tstamp = purple_str_to_time(stamp, TRUE, NULL, NULL, NULL);
 			if (tstamp != 0) {
 				presence->idle = time(NULL) - tstamp;
+				presence->adjust_idle_for_delay = FALSE;
 				if(presence->idle < 0) {
 					purple_debug_warning("jabber", "Received bogus idle timestamp %s\n", stamp);
 					presence->idle = 0;
-				} else {
-					presence->absolute_idle = TRUE;
 				}
 			}
 		}
+		g_free(stamp);
 	}
 }
 
@@ -1198,7 +1198,7 @@ parse_idle(JabberStream *js, JabberPrese
 	const gchar *seconds = xmlnode_get_attrib(query, "seconds");
 	if (seconds) {
 		presence->idle = atoi(seconds);
-		presence->absolute_idle = FALSE;
+		presence->adjust_idle_for_delay = TRUE;
 		if (presence->idle < 0) {
 			purple_debug_warning("jabber", "Received bogus idle time %s\n", seconds);
 			presence->idle = 0;
diff --git a/libpurple/protocols/jabber/presence.h b/libpurple/protocols/jabber/presence.h
--- a/libpurple/protocols/jabber/presence.h
+++ b/libpurple/protocols/jabber/presence.h
@@ -71,9 +71,7 @@ struct _JabberPresence {
 	gboolean delayed;
 	time_t sent;
 	int idle;
-	/* this is TRUE if we got the idle time as an absolute timestamp
-	 * and it shouldn't be adjusted if the presence was delayed */
-	gboolean absolute_idle;
+	gboolean adjust_idle_for_delay;
 };
 
 typedef void (JabberPresenceHandler)(JabberStream *js, JabberPresence *presence,



More information about the Commits mailing list