[Pidgin] #5447: Buddy list sort by recent activity

Pidgin trac at pidgin.im
Tue Dec 2 18:11:56 EST 2008


#5447: Buddy list sort by recent activity
-------------------------------------+--------------------------------------
 Reporter:  cconnett                 |        Owner:  rlaager     
     Type:  patch                    |       Status:  new         
Milestone:                           |    Component:  pidgin (gtk)
  Version:  2.5.2                    |   Resolution:              
 Keywords:  buddylist sort activity  |  
-------------------------------------+--------------------------------------

Comment(by rlaager):

 The hunk in the patch (near the top) with the comment that says lu was
 already freed is clearly bogus. You can't be accessing data after it's
 been freed. You want the code to be something like this instead:

 {{{
         lu = g_new(struct _purple_logsize_user, 1);
         lu->name = g_strdup(purple_normalize(log->account, log->name));
         lu->account = log->account;

         if(g_hash_table_lookup_extended(logsize_users, lu, NULL,
 &ptrsize)) {
                 char *tmp = lu->name;

                 total = GPOINTER_TO_INT(ptrsize);
                 total += written;
                 g_hash_table_replace(logsize_users, lu,
 GINT_TO_POINTER(total));

                 /* The hash table takes ownership of lu, so we build a
                  * new one for the code below. */
                 lu = g_new(struct _purple_logsize_user, 1);
                 lu->name = g_strdup(tmp);
                 lu->account = log->account;
         }

         if(g_hash_table_lookup_extended(logsize_users_decayed, lu, NULL,
 &ptrsize)) {
                 total = GPOINTER_TO_INT(ptrsize);
                 total += written;
                 g_hash_table_replace(logsize_users_decayed, lu,
 GINT_TO_POINTER(total));
         } else {
                 g_free(lu->name);
                 g_free(lu);
         }
 }}}

 Notice how if we don't need the first lu struct, we reuse it for the
 second lookup. However, if we use it the first time, we build another.

 You have // comments. We don't allow those in Pidgin.

 Even more minor... We typically put the @since under the @return, I think.

 Let's be bold. Can you update this patch to replace the existing sort
 method?

-- 
Ticket URL: <http://developer.pidgin.im/ticket/5447#comment:13>
Pidgin <http://pidgin.im>
Pidgin


More information about the Tracker mailing list