diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2007-07-02 23:12:03 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2007-07-02 23:12:03 +0100 |
commit | 9da0bbfd42609f0f3864b5a16a3c1c378b7217c9 (patch) | |
tree | 080ab25a0fd949429c33ba125b9df189807d0d3c | |
parent | 5d7dc007a418be0c897000e888e747047729c756 (diff) |
Added (and using) jabber_chat_free() for better memory management, fixed
channel name generation code in root_commands.c and fixed one memory leak
in jabber_buddy_remove_bare().
-rw-r--r-- | protocols/jabber/conference.c | 21 | ||||
-rw-r--r-- | protocols/jabber/jabber.c | 2 | ||||
-rw-r--r-- | protocols/jabber/jabber.h | 1 | ||||
-rw-r--r-- | protocols/jabber/jabber_util.c | 19 | ||||
-rw-r--r-- | root_commands.c | 2 |
5 files changed, 28 insertions, 17 deletions
diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c index 24b5631a..f49dbd1c 100644 --- a/protocols/jabber/conference.c +++ b/protocols/jabber/conference.c @@ -64,6 +64,19 @@ struct groupchat *jabber_chat_join( struct im_connection *ic, char *room, char * return c; } +void jabber_chat_free( struct groupchat *c ) +{ + struct jabber_chat *jc = c->data; + + jabber_buddy_remove_bare( c->ic, jc->name ); + + g_free( jc->my_full_jid ); + g_free( jc->name ); + g_free( jc ); + + imcb_chat_free( c ); +} + int jabber_chat_msg( struct groupchat *c, char *message, int flags ) { struct im_connection *ic = c->ic; @@ -191,13 +204,7 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu if( s ) *s = '/'; if( bud == jc->me ) - { - jabber_buddy_remove_bare( ic, jc->name ); - - g_free( jc->name ); - g_free( jc ); - imcb_chat_free( chat ); - } + jabber_chat_free( chat ); } } diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index 9df1dc74..9176cd68 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -197,7 +197,7 @@ static void jabber_logout( struct im_connection *ic ) jabber_end_stream( ic ); while( ic->groupchats ) - imcb_chat_free( ic->groupchats ); + jabber_chat_free( ic->groupchats ); if( jd->r_inpa >= 0 ) b_event_remove( jd->r_inpa ); diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index bc639fea..90c1e9f6 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -219,6 +219,7 @@ gboolean sasl_supported( struct im_connection *ic ); /* conference.c */ struct groupchat *jabber_chat_join( struct im_connection *ic, char *room, char *nick, char *password ); +void jabber_chat_free( struct groupchat *c ); int jabber_chat_msg( struct groupchat *ic, char *message, int flags ); int jabber_chat_leave( struct groupchat *c, const char *reason ); void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bud, struct xt_node *node ); diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 53f97ff0..5b91c5ed 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -541,26 +541,31 @@ int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ ) /* Remove a buddy completely; removes all resources that belong to the specified bare JID. Use this when removing someone from the contact list, for example. */ -int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid_ ) +int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid ) { struct jabber_data *jd = ic->proto_data; struct jabber_buddy *bud, *next; - char *bare_jid; - if( strchr( bare_jid_, '/' ) ) + if( strchr( bare_jid, '/' ) ) return 0; - bare_jid = jabber_normalize( bare_jid_ ); - - if( ( bud = g_hash_table_lookup( jd->buddies, bare_jid ) ) ) + if( ( bud = jabber_buddy_by_jid( ic, bare_jid, GET_BUDDY_FIRST ) ) ) { /* Most important: Remove the hash reference. We don't know this buddy anymore. */ g_hash_table_remove( jd->buddies, bud->bare_jid ); + g_free( bud->bare_jid ); /* Deallocate the linked list of resources. */ while( bud ) { + /* ext_jid && anonymous means that this buddy is + specific to one groupchat (the one we're + currently cleaning up) so it can be deleted + completely. */ + if( bud->ext_jid && bud->flags & JBFLAG_IS_ANONYMOUS ) + imcb_remove_buddy( ic, bud->ext_jid, NULL ); + next = bud->next; g_free( bud->ext_jid ); g_free( bud->full_jid ); @@ -569,12 +574,10 @@ int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid_ ) bud = next; } - g_free( bare_jid ); return 1; } else { - g_free( bare_jid ); return 0; } } diff --git a/root_commands.c b/root_commands.c index 8ffebd8e..0f9f776c 100644 --- a/root_commands.c +++ b/root_commands.c @@ -911,7 +911,7 @@ static void cmd_join_chat( irc_t *irc, char **cmd ) chat = cmd[2]; if( cmd[3] ) { - if( channel[0] != '#' && channel[0] != '&' ) + if( cmd[3][0] != '#' && cmd[3][0] != '&' ) channel = g_strdup_printf( "&%s", cmd[3] ); else channel = g_strdup( cmd[3] ); |