[Xfce4-commits] <ristretto:ristretto-0.0> Fix memory leaks
Stephan Arts
noreply at xfce.org
Sun Oct 23 19:21:15 CEST 2011
Updating branch refs/heads/ristretto-0.0
to a8b0d38c4754b693e3821acdb4f7a5e24233e9e3 (commit)
from 4cb99fa5451db6c56b203e8d8c7aead44d084d39 (commit)
commit a8b0d38c4754b693e3821acdb4f7a5e24233e9e3
Author: Stephan Arts <stephan at xfce.org>
Date: Thu Oct 15 23:18:44 2009 +0200
Fix memory leaks
ChangeLog | 9 +++++++++
src/image.c | 8 ++++++--
src/image.h | 2 +-
src/image_cache.c | 21 +++++++++++++--------
src/image_cache.h | 1 +
src/picture_viewer.c | 4 +++-
src/settings.c | 2 +-
7 files changed, 34 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2d7108b..8010648 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2009-10-08 Stephan Arts <stephan at xfce.org>
+ * src/image.c,
+ src/image.h,
+ src/image_cache.h,
+ src/image_cache.c: Fixed memory leak in image-cache
+ * src/picture_viewer.c: Fixed memory leak in paint function
+ * src/settings.c: Fix default setting for slideshow timeout
+
+2009-10-08 Stephan Arts <stephan at xfce.org>
+
* src/thumbnail_bar.c,
src/thumbnail_bar.h: Change looks of the thumbnailbar
diff --git a/src/image.c b/src/image.c
index a6a9bb5..a1a83af 100644
--- a/src/image.c
+++ b/src/image.c
@@ -177,6 +177,7 @@ static void
rstto_image_dispose (GObject *object)
{
RsttoImage *image = RSTTO_IMAGE (object);
+ RsttoImageCache *cache;
if(image->priv->cancellable)
{
@@ -214,6 +215,8 @@ rstto_image_dispose (GObject *object)
{
g_object_unref (image->priv->pixbuf);
image->priv->pixbuf = NULL;
+ cache = rstto_image_cache_new ();
+ rstto_image_cache_pop_image (cache, image);
}
if (image->priv->buffer)
@@ -705,7 +708,7 @@ cb_rstto_image_update(RsttoImage *image)
return TRUE;
}
-guint
+guint64
rstto_image_get_size (RsttoImage *image)
{
GdkPixbuf *pixbuf = rstto_image_get_pixbuf (image);
@@ -717,7 +720,8 @@ rstto_image_get_size (RsttoImage *image)
/* multiplied by 2 since it is unclear why the nr of bytes
* in memory is twice what is calculated here, based on the dimensions
*/
- return rowstride * height * 2;
+ //return rowstride * height * 2;
+ return (guint64)rowstride * (guint64)height;
}
return 0;
}
diff --git a/src/image.h b/src/image.h
index 50e91d0..2a996bd 100644
--- a/src/image.h
+++ b/src/image.h
@@ -83,7 +83,7 @@ GFile *rstto_image_get_file (RsttoImage *image);
void rstto_image_unload (RsttoImage *image);
gboolean rstto_image_load (RsttoImage *image, gboolean empty_cache, guint max_size, gboolean preload, GError **error);
-guint rstto_image_get_size (RsttoImage *image);
+guint64 rstto_image_get_size (RsttoImage *image);
void
rstto_image_set_orientation (RsttoImage *image, RsttoImageOrientation orientation);
diff --git a/src/image_cache.c b/src/image_cache.c
index a37cda0..f8b61f0 100644
--- a/src/image_cache.c
+++ b/src/image_cache.c
@@ -87,12 +87,22 @@ rstto_image_cache_class_init (GObjectClass *object_class)
}
gboolean
+rstto_image_cache_pop_image (RsttoImageCache *cache, RsttoImage *image)
+{
+ if (cache->cache_list)
+ {
+ rstto_image_unload (image);
+ cache->cache_list = g_list_remove_all (cache->cache_list, image);
+ }
+}
+
+gboolean
rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolean last)
{
gboolean retval = FALSE;
RsttoSettings *settings = rstto_settings_new();
gboolean cache_enabled;
- guint size = 0;
+ guint64 size = 0;
guint cache_size = 0;
RsttoImage *c_image;
GList *iter = NULL;
@@ -107,8 +117,6 @@ rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolea
cache->cache_list = g_list_remove_all (cache->cache_list, image);
}
- g_object_ref (image);
-
if (last)
{
cache->cache_list = g_list_append (cache->cache_list, image);
@@ -128,7 +136,6 @@ rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolea
c_image = g_list_last (cache->cache_list)->data;
rstto_image_unload (c_image);
cache->cache_list = g_list_remove (cache->cache_list, c_image);
- g_object_unref (c_image);
retval = TRUE;
}
}
@@ -140,22 +147,20 @@ rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolea
for (iter = cache->cache_list->next; iter != NULL; iter = g_list_next (iter))
{
c_image = iter->data;
- size += rstto_image_get_size (c_image);
- if (size > (cache_size*1000000))
+ if (size > (guint64)(cache_size*1000000))
{
rstto_image_unload (c_image);
cache->cache_list = g_list_remove (cache->cache_list, c_image);
- g_object_unref (c_image);
iter = g_list_previous(iter);
retval = TRUE;
}
else
{
+ size = size + rstto_image_get_size (c_image);
if (rstto_image_get_size (c_image) == 0)
{
rstto_image_unload (c_image);
cache->cache_list = g_list_remove (cache->cache_list, c_image);
- g_object_unref (c_image);
iter = g_list_previous(iter);
}
}
diff --git a/src/image_cache.h b/src/image_cache.h
index 01e1adc..15ef87d 100644
--- a/src/image_cache.h
+++ b/src/image_cache.h
@@ -49,6 +49,7 @@ GType rstto_image_cache_get_type (void);
RsttoImageCache *rstto_image_cache_new ();
gboolean rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolean last);
+gboolean rstto_image_cache_pop_image (RsttoImageCache *cache, RsttoImage *image);
void rstto_image_cache_clear (RsttoImageCache *cache);
diff --git a/src/picture_viewer.c b/src/picture_viewer.c
index 6bbcafc..0eb1897 100644
--- a/src/picture_viewer.c
+++ b/src/picture_viewer.c
@@ -613,7 +613,9 @@ rstto_picture_viewer_paint (GtkWidget *widget)
if (pixbuf)
{
gdk_pixbuf_saturate_and_pixelate (pixbuf, pixbuf, 0, TRUE);
- pixbuf = gdk_pixbuf_composite_color_simple (pixbuf, (size*0.8), (size*0.8), GDK_INTERP_BILINEAR, 40, 40, bg_color->pixel, bg_color->pixel);
+ GdkPixbuf *n_pixbuf = gdk_pixbuf_composite_color_simple (pixbuf, (size*0.8), (size*0.8), GDK_INTERP_BILINEAR, 40, 40, bg_color->pixel, bg_color->pixel);
+ g_object_unref (pixbuf);
+ pixbuf = n_pixbuf;
x1 = (widget->allocation.width-gdk_pixbuf_get_width(pixbuf))<0?0:(widget->allocation.width-gdk_pixbuf_get_width(pixbuf))/2;
y1 = (widget->allocation.height-gdk_pixbuf_get_height(pixbuf))<0?0:(widget->allocation.height-gdk_pixbuf_get_height(pixbuf))/2;
diff --git a/src/settings.c b/src/settings.c
index 1346732..f994c95 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -147,7 +147,7 @@ rstto_settings_init (GObject *object)
accelmap_path = NULL;
}
- settings->priv->slideshow_timeout = 5000;
+ settings->priv->slideshow_timeout = 5;
settings->priv->bgcolor = g_new0 (GdkColor, 1);
settings->priv->bgcolor_fullscreen = g_new0 (GdkColor, 1);
settings->priv->image_quality = 2000000;
More information about the Xfce4-commits
mailing list