--- a/libpurple/imgstore.c Mon Jan 21 16:28:56 2013 -0800 +++ b/libpurple/imgstore.c Mon Jan 21 18:06:01 2013 -0800 @@ -89,20 +89,22 @@ purple_imgstore_add_with_id(gpointer data, size_t size, const char *filename) { PurpleStoredImage *img = purple_imgstore_add(data, size, filename); - if (img) { - /* - * Use the next unused id number. We do it in a loop on the - * off chance that nextid wraps back around to 0 and the hash - * table still contains entries from the first time around. - */ - do { - img->id = ++nextid; - } while (img->id == 0 || g_hash_table_lookup(imgstore, &(img->id)) != NULL); - - g_hash_table_insert(imgstore, &(img->id), img); + if (!img) { + return 0; } - return (img ? img->id : 0); + /* + * Use the next unused id number. We do it in a loop on the + * off chance that nextid wraps back around to 0 and the hash + * table still contains entries from the first time around. + */ + do { + img->id = ++nextid; + } while (img->id == 0 || g_hash_table_lookup(imgstore, &(img->id)) != NULL); + + g_hash_table_insert(imgstore, &(img->id), img); + + return img->id; } PurpleStoredImage *purple_imgstore_find_by_id(int id) {