diff pidgin-twitter.c @ 167:10516b7b05a9

- ceased use of purple_imgstore_* - fixed for some memory leakage.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 29 Jul 2008 19:20:20 +0900
parents af85daac1a95
children 56e3873e58a8
line wrap: on
line diff
--- a/pidgin-twitter.c	Tue Jul 29 14:49:12 2008 +0900
+++ b/pidgin-twitter.c	Tue Jul 29 19:20:20 2008 +0900
@@ -476,6 +476,9 @@
         }
      }
 
+     xmlFreeDoc(doc);
+     xmlCleanupParser();
+
      /* process statuseslist */
      for(stp = statuseslist; stp; stp=stp->next) {
          status_t *st = (status_t *)stp->data;
@@ -657,6 +660,9 @@
             }
         }
 
+        xmlFreeDoc(doc);
+        xmlCleanupParser();
+
     } else {
         gchar *m;
         m = g_strdup_printf("%s<BR>%s",
@@ -1550,7 +1556,6 @@
     GtkIMHtml *target_imhtml = NULL;
     GtkTextBuffer *target_buffer = NULL;
     GtkTextIter insertion_point;
-    gint icon_id;
     icon_data *data = NULL;
     GHashTable *hash = NULL;
 
@@ -1608,10 +1613,6 @@
     if(hash)
         data = (icon_data *)g_hash_table_lookup(hash, user_name);
 
-    if(data)
-        icon_id = data->icon_id;
-    else
-        icon_id = 0;
 
     /* in this function, we put an icon for pending marks. we should
      * not invalidate the icon here, otherwise it may result in
@@ -1631,17 +1632,15 @@
     }
 #endif
 
-    if(!icon_id) {
+    if(!data || !data->pixbuf) {
         return;
     }
 
     /* insert icon actually */
     if(purple_prefs_get_bool(OPT_SHOW_ICON)) {
-        PurpleStoredImage *img = purple_imgstore_find_by_id(icon_id);
-        const GdkPixbuf *pixbuf = purple_imgstore_get_data(img);
         gtk_text_buffer_insert_pixbuf(target_buffer,
                                       &insertion_point,
-                                      (GdkPixbuf *)pixbuf);
+                                      data->pixbuf);
         data->use_count++;
     }
     gtk_text_buffer_delete_mark(target_buffer, requested_mark);
@@ -1692,6 +1691,7 @@
         g_list_free(mark_list);
         data->request_list = NULL;
     }
+
     g_free(gotdata->user_name);
     g_free(gotdata);
 }
@@ -1814,7 +1814,7 @@
         size = DEFAULT_ICON_SIZE;
 
     dest = gdk_pixbuf_scale_simple(src, size, size, GDK_INTERP_HYPER);
-    gdk_pixbuf_unref (src);
+    gdk_pixbuf_unref(src);
 
     return dest;
 }
@@ -1835,7 +1835,6 @@
     gchar *user_name = gotdata->user_name;
     gint service = gotdata->service;
 
-    gint icon_id;
     icon_data *data = NULL;
     GHashTable *hash = NULL;
     GdkPixbuf *pixbuf = NULL;
@@ -1876,7 +1875,7 @@
         data->fetch_data = NULL;
 
         /* return if user's icon had been downloaded */
-        if(data->icon_id > 0) {
+        if(data->pixbuf) {
             twitter_debug("%s's icon has already been downloaded\n",
                           user_name);
 
@@ -1889,18 +1888,18 @@
     if(!pixbuf)
         goto fin_got_icon_cb;
 
-    icon_id =
-        purple_imgstore_add_with_id(pixbuf,
-                                    gdk_pixbuf_get_rowstride(pixbuf) *
-                                    gdk_pixbuf_get_height(pixbuf),
-                                    user_name);
 
     if(!data) {
         twitter_debug("allocate icon_data (shouldn't be called)\n");
         data = g_new0(icon_data, 1);
     }
 
-    data->icon_id = icon_id;
+    data->pixbuf = pixbuf;
+
+    twitter_debug("new icon pixbuf = %p size = %d\n",
+                  pixbuf,
+                  gdk_pixbuf_get_rowstride(pixbuf) *
+                  gdk_pixbuf_get_height(pixbuf));
 
     if(hash)
         g_hash_table_insert(hash, g_strdup(user_name), data);
@@ -1953,8 +1952,8 @@
         data->mtime = time(NULL);
     }
 
-    twitter_debug("Downloading %s's icon has been complete.(icon_id = %d)\n",
-        user_name, icon_id);
+    twitter_debug("Downloading %s's icon has been complete.\n",
+        user_name);
 
     /* Insert the icon to messages that had been received. */
     insert_requested_icon(user_name, service);
@@ -1999,10 +1998,9 @@
     /* since this function is called after mark_icon_for_user(), data
      * must exist here. */
     data = (icon_data *)g_hash_table_lookup(hash, user_name);
-//    g_hash_table_insert(hash, g_strdup(user_name), data); // XXX ???
 
     /* if img has been registerd, just return */
-    if(data->icon_id > 0)
+    if(data && data->pixbuf)
         return;
 
     /* check if saved file exists */
@@ -2035,14 +2033,15 @@
                     data->mtime = buf.st_mtime;
 
                 pixbuf = make_scaled_pixbuf(imgdata, len);
+                g_free(imgdata);
 
                 if(pixbuf) {
-                    data->icon_id =
-                        purple_imgstore_add_with_id(
-                            pixbuf,
-                            gdk_pixbuf_get_rowstride(pixbuf) *
-                            gdk_pixbuf_get_height(pixbuf),
-                            user_name);
+                    data->pixbuf = pixbuf;
+
+                    twitter_debug("new icon pixbuf = %p size = %d\n",
+                                  pixbuf,
+                                  gdk_pixbuf_get_rowstride(pixbuf) *
+                                  gdk_pixbuf_get_height(pixbuf));
 
                     data->img_type = *extp;
 
@@ -2175,7 +2174,6 @@
     GtkIMHtml *imhtml;
     GtkTextBuffer *text_buffer;
     GtkTextIter insertion_point;
-    gint icon_id = 0;
     gint service = get_service_type(conv);
     icon_data *data = NULL;
     gint linenumber;
@@ -2229,17 +2227,17 @@
         data = g_hash_table_lookup(hash, user_name);
 
     if(data) {
-        icon_id = data->icon_id;
-
         /* check validity of icon */
         int count_thres = purple_prefs_get_int(OPT_ICON_MAX_COUNT);
-        int days_thres = DAYS_TO_SECONDS(purple_prefs_get_int(OPT_ICON_MAX_DAYS));
+        int days_thres = DAYS_TO_SECONDS(
+            purple_prefs_get_int(OPT_ICON_MAX_DAYS));
 
         if(data->use_count > count_thres ||
            (data->mtime && ((time(NULL) - data->mtime)) > days_thres)) {
-            twitter_debug("count=%d mtime=%d\n", data->use_count, (int)(data->mtime));
-            icon_id = 0;
-            data->icon_id = 0;
+            twitter_debug("count=%d mtime=%d\n",
+                          data->use_count, (int)(data->mtime));
+            g_object_unref(data->pixbuf);
+            data->pixbuf = NULL;
             data->use_count = 0;
             data->mtime = time(NULL); //xxx not good
             renew = TRUE;
@@ -2248,7 +2246,7 @@
 
     /* if we don't have the icon for this user, put a mark instead and
      * request the icon */
-    if(!icon_id) {
+    if(!data || !data->pixbuf) {
         twitter_debug("%s's icon is not in memory.\n", user_name);
         mark_icon_for_user(gtk_text_buffer_create_mark(
                                text_buffer, NULL, &insertion_point, FALSE),
@@ -2261,11 +2259,9 @@
 
     /* if we have icon for this user, insert icon immediately */
     if(purple_prefs_get_bool(OPT_SHOW_ICON)) {
-        PurpleStoredImage *img = purple_imgstore_find_by_id(icon_id);
-        const GdkPixbuf *pixbuf = purple_imgstore_get_data(img);
         gtk_text_buffer_insert_pixbuf(text_buffer,
                                       &insertion_point,
-                                      (GdkPixbuf *)pixbuf);
+                                      data->pixbuf);
         data->use_count++;
     }
     g_free(user_name); user_name = NULL;
@@ -2503,16 +2499,9 @@
     icon_data *data = (icon_data *)value;
 
     g_return_if_fail(data != NULL);
-    g_return_if_fail(data->icon_id > 0);
-
-    /* img->data is managed by gdkpixbuf, so we should not free here. */
-#if 0
-    PurpleStoredImage *img = purple_imgstore_find_by_id(data->icon_id);
-    if(img)
-        purple_imgstore_unref_by_id(data->icon_id);
-#endif
-
-    data->icon_id = 0;
+
+    g_object_unref(data->pixbuf);
+    data->pixbuf = NULL;
 }
 
 static void
@@ -2612,6 +2601,7 @@
     gtk_builder_add_from_file(builder, filename, &err);
     if(err) {
         twitter_debug("%s\n", err->message);
+        g_free(filename);
         return NULL;
     }