From f277225d33d93d228ce1c953e050331c501e646b Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 6 Jun 2010 22:58:46 +0100 Subject: Use mkstemp() instead of just a tilde-file when writing new configs to a temporary file. This solves hard-to-debug issues where for example the user hand-edited his configs as root and left a root-owned user.xml~ file behind. --- storage_xml.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/storage_xml.c b/storage_xml.c index 8c524ca9..071fcd11 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -403,8 +403,8 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) if( !overwrite && g_access( path, F_OK ) == 0 ) return STORAGE_ALREADY_EXISTS; - strcat( path, "~" ); - if( ( fd = open( path, O_WRONLY | O_CREAT | O_TRUNC, 0600 ) ) < 0 ) + strcat( path, ".XXXXXX" ); + if( ( fd = mkstemp( path ) ) < 0 ) { irc_usermsg( irc, "Error while opening configuration file." ); return STORAGE_OTHER_ERROR; @@ -498,7 +498,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) fsync( fd ); close( fd ); - path2 = g_strndup( path, strlen( path ) - 1 ); + path2 = g_strndup( path, strlen( path ) - 7 ); if( rename( path, path2 ) != 0 ) { irc_usermsg( irc, "Error while renaming temporary configuration file." ); -- cgit v1.2.3 From 04a927cb733e2c47424569550a2faeb108094636 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 8 Jun 2010 00:04:58 +0100 Subject: Fixing some memory leakage. --- protocols/jabber/jabber.c | 2 ++ protocols/jabber/jabber.h | 1 + protocols/jabber/jabber_util.c | 26 ++++++++++++++++++++++++++ protocols/twitter/twitter.c | 2 ++ 4 files changed, 31 insertions(+) diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index 86320ada..8bb44691 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -285,6 +285,8 @@ static void jabber_logout( struct im_connection *ic ) if( jd->node_cache ) g_hash_table_destroy( jd->node_cache ); + jabber_buddy_remove_all( ic ); + xt_free( jd->xt ); g_free( jd->away_message ); diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index 40cf3957..3f4144b8 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -229,6 +229,7 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid, g struct jabber_buddy *jabber_buddy_by_ext_jid( struct im_connection *ic, char *jid, get_buddy_flags_t flags ); int jabber_buddy_remove( struct im_connection *ic, char *full_jid ); int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid ); +void jabber_buddy_remove_all( struct im_connection *ic ); time_t jabber_get_timestamp( struct xt_node *xt ); struct jabber_error *jabber_error_parse( struct xt_node *node, char *xmlns ); void jabber_error_free( struct jabber_error *err ); diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index b8b625f7..651b7068 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -664,6 +664,32 @@ int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid ) } } +static gboolean jabber_buddy_remove_all_cb( gpointer key, gpointer value, gpointer data ) +{ + struct jabber_buddy *bud, *next; + + bud = value; + while( bud ) + { + next = bud->next; + g_free( bud->ext_jid ); + g_free( bud->full_jid ); + g_free( bud->away_message ); + g_free( bud ); + bud = next; + } + + return TRUE; +} + +void jabber_buddy_remove_all( struct im_connection *ic ) +{ + struct jabber_data *jd = ic->proto_data; + + g_hash_table_foreach_remove( jd->buddies, jabber_buddy_remove_all_cb, NULL ); + g_hash_table_destroy( jd->buddies ); +} + time_t jabber_get_timestamp( struct xt_node *xt ) { struct xt_node *c; diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index a5fc68ab..db893e17 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -235,6 +235,8 @@ static void twitter_logout( struct im_connection *ic ) if( td ) { oauth_info_free( td->oauth_info ); + g_free( td->url_host ); + g_free( td->url_path ); g_free( td->pass ); g_free( td ); } -- cgit v1.2.3