[gthumb: 13/129] fixed memory leak when calling gth_image_viewer_get_current_pixbuf
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 13/129] fixed memory leak when calling gth_image_viewer_get_current_pixbuf
- Date: Wed, 27 Apr 2011 20:51:28 +0000 (UTC)
commit 5f14d95db70778d37b35c636078255d1540286d6
Author: Paolo Bacchilega <paobac src gnome org>
Date: Thu Apr 14 22:29:01 2011 +0200
fixed memory leak when calling gth_image_viewer_get_current_pixbuf
extensions/desktop_background/actions.c | 2 +-
.../file_tools/gth-file-tool-adjust-colors.c | 1 -
extensions/file_tools/gth-file-tool-crop.c | 2 -
extensions/file_tools/gth-file-tool-desaturate.c | 1 +
extensions/file_tools/gth-file-tool-enhance.c | 1 +
extensions/file_tools/gth-file-tool-equalize.c | 1 +
extensions/file_tools/gth-file-tool-flip.c | 3 +-
extensions/file_tools/gth-file-tool-mirror.c | 1 +
extensions/file_tools/gth-file-tool-negative.c | 1 +
extensions/file_tools/gth-file-tool-resize.c | 2 -
extensions/file_tools/gth-file-tool-rotate-left.c | 1 +
extensions/file_tools/gth-file-tool-rotate-right.c | 1 +
extensions/file_tools/gth-file-tool-rotate.c | 11 ++++++--
extensions/file_tools/gth-file-tool-sharpen.c | 1 -
extensions/file_tools/gth-image-rotator.c | 11 ++++++--
extensions/image_print/actions.c | 4 +-
extensions/image_viewer/gth-image-histogram.c | 4 ++-
extensions/image_viewer/gth-image-viewer-page.c | 24 ++++++++++++++-----
extensions/red_eye_removal/gth-file-tool-red-eye.c | 4 +--
gthumb/gth-image-viewer.c | 17 +------------
20 files changed, 51 insertions(+), 42 deletions(-)
---
diff --git a/extensions/desktop_background/actions.c b/extensions/desktop_background/actions.c
index f36b489..edaae75 100644
--- a/extensions/desktop_background/actions.c
+++ b/extensions/desktop_background/actions.c
@@ -246,7 +246,7 @@ gth_browser_activate_action_tool_desktop_background (GtkAction *action,
if (viewer_page != NULL) {
GdkPixbuf *pixbuf;
- pixbuf = g_object_ref (gth_image_viewer_page_get_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page)));
+ pixbuf = gth_image_viewer_page_get_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page));
file_data = gth_file_data_new (wdata->new_file, NULL);
_gdk_pixbuf_save_async (pixbuf,
file_data,
diff --git a/extensions/file_tools/gth-file-tool-adjust-colors.c b/extensions/file_tools/gth-file-tool-adjust-colors.c
index c9fad2f..ea2b614 100644
--- a/extensions/file_tools/gth-file-tool-adjust-colors.c
+++ b/extensions/file_tools/gth-file-tool-adjust-colors.c
@@ -362,7 +362,6 @@ gth_file_tool_adjust_colors_get_options (GthFileTool *base)
if (self->priv->src_pixbuf == NULL)
return NULL;
- self->priv->src_pixbuf = g_object_ref (self->priv->src_pixbuf);
self->priv->dest_pixbuf = NULL;
self->priv->builder = _gtk_builder_new_from_file ("adjust-colors-options.ui", "file_tools");
diff --git a/extensions/file_tools/gth-file-tool-crop.c b/extensions/file_tools/gth-file-tool-crop.c
index 5bdbe53..4f88e88 100644
--- a/extensions/file_tools/gth-file-tool-crop.c
+++ b/extensions/file_tools/gth-file-tool-crop.c
@@ -404,8 +404,6 @@ gth_file_tool_crop_get_options (GthFileTool *base)
if (self->priv->src_pixbuf == NULL)
return NULL;
- g_object_ref (self->priv->src_pixbuf);
-
self->priv->pixbuf_width = gdk_pixbuf_get_width (self->priv->src_pixbuf);
self->priv->pixbuf_height = gdk_pixbuf_get_height (self->priv->src_pixbuf);
_gtk_widget_get_screen_size (window, &self->priv->screen_width, &self->priv->screen_height);
diff --git a/extensions/file_tools/gth-file-tool-desaturate.c b/extensions/file_tools/gth-file-tool-desaturate.c
index 33750b9..724052b 100644
--- a/extensions/file_tools/gth-file-tool-desaturate.c
+++ b/extensions/file_tools/gth-file-tool-desaturate.c
@@ -109,6 +109,7 @@ gth_file_tool_desaturate_activate (GthFileTool *base)
gth_browser_exec_task (GTH_BROWSER (window), task, FALSE);
g_object_unref (task);
+ g_object_unref (src_pixbuf);
}
diff --git a/extensions/file_tools/gth-file-tool-enhance.c b/extensions/file_tools/gth-file-tool-enhance.c
index bd1ef56..f9c5517 100644
--- a/extensions/file_tools/gth-file-tool-enhance.c
+++ b/extensions/file_tools/gth-file-tool-enhance.c
@@ -260,6 +260,7 @@ gth_file_tool_enhance_activate (GthFileTool *base)
gth_browser_exec_task (GTH_BROWSER (window), task, FALSE);
g_object_unref (task);
+ g_object_unref (src_pixbuf);
}
diff --git a/extensions/file_tools/gth-file-tool-equalize.c b/extensions/file_tools/gth-file-tool-equalize.c
index 242cf05..65d216f 100644
--- a/extensions/file_tools/gth-file-tool-equalize.c
+++ b/extensions/file_tools/gth-file-tool-equalize.c
@@ -176,6 +176,7 @@ gth_file_tool_equalize_activate (GthFileTool *base)
gth_browser_exec_task (GTH_BROWSER (window), task, FALSE);
g_object_unref (task);
+ g_object_unref (src_pixbuf);
}
diff --git a/extensions/file_tools/gth-file-tool-flip.c b/extensions/file_tools/gth-file-tool-flip.c
index 36d94c7..b2cb0b1 100644
--- a/extensions/file_tools/gth-file-tool-flip.c
+++ b/extensions/file_tools/gth-file-tool-flip.c
@@ -41,7 +41,7 @@ gth_file_tool_flip_activate (GthFileTool *base)
return;
viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
- src_pixbuf = gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (viewer));
+ src_pixbuf = gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (viewer)); /* FIXME: use the cairo_surface directly */
if (src_pixbuf == NULL)
return;
@@ -49,6 +49,7 @@ gth_file_tool_flip_activate (GthFileTool *base)
gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), dest_pixbuf, TRUE);
g_object_unref (dest_pixbuf);
+ g_object_unref (src_pixbuf);
}
diff --git a/extensions/file_tools/gth-file-tool-mirror.c b/extensions/file_tools/gth-file-tool-mirror.c
index 22ad1a1..454caa5 100644
--- a/extensions/file_tools/gth-file-tool-mirror.c
+++ b/extensions/file_tools/gth-file-tool-mirror.c
@@ -49,6 +49,7 @@ gth_file_tool_mirror_activate (GthFileTool *base)
gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), dest_pixbuf, TRUE);
g_object_unref (dest_pixbuf);
+ g_object_unref (src_pixbuf);
}
diff --git a/extensions/file_tools/gth-file-tool-negative.c b/extensions/file_tools/gth-file-tool-negative.c
index e7ff82f..c5f9582 100644
--- a/extensions/file_tools/gth-file-tool-negative.c
+++ b/extensions/file_tools/gth-file-tool-negative.c
@@ -91,6 +91,7 @@ gth_file_tool_negative_activate (GthFileTool *base)
gth_browser_exec_task (GTH_BROWSER (window), task, FALSE);
g_object_unref (task);
+ g_object_unref (src_pixbuf);
}
diff --git a/extensions/file_tools/gth-file-tool-resize.c b/extensions/file_tools/gth-file-tool-resize.c
index 63f1ca2..109dac5 100644
--- a/extensions/file_tools/gth-file-tool-resize.c
+++ b/extensions/file_tools/gth-file-tool-resize.c
@@ -384,8 +384,6 @@ gth_file_tool_resize_get_options (GthFileTool *base)
if (self->priv->src_pixbuf == NULL)
return NULL;
- g_object_ref (self->priv->src_pixbuf);
-
self->priv->pixbuf_width = gdk_pixbuf_get_width (self->priv->src_pixbuf);
self->priv->pixbuf_height = gdk_pixbuf_get_height (self->priv->src_pixbuf);
_gtk_widget_get_screen_size (window, &self->priv->screen_width, &self->priv->screen_height);
diff --git a/extensions/file_tools/gth-file-tool-rotate-left.c b/extensions/file_tools/gth-file-tool-rotate-left.c
index bb1168e..596fd8f 100644
--- a/extensions/file_tools/gth-file-tool-rotate-left.c
+++ b/extensions/file_tools/gth-file-tool-rotate-left.c
@@ -49,6 +49,7 @@ gth_file_tool_rotate_left_activate (GthFileTool *base)
gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), dest_pixbuf, TRUE);
g_object_unref (dest_pixbuf);
+ g_object_unref (src_pixbuf);
}
diff --git a/extensions/file_tools/gth-file-tool-rotate-right.c b/extensions/file_tools/gth-file-tool-rotate-right.c
index cdf1b4a..1e6bff6 100644
--- a/extensions/file_tools/gth-file-tool-rotate-right.c
+++ b/extensions/file_tools/gth-file-tool-rotate-right.c
@@ -49,6 +49,7 @@ gth_file_tool_rotate_right_activate (GthFileTool *base)
gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), dest_pixbuf, TRUE);
g_object_unref (dest_pixbuf);
+ g_object_unref (src_pixbuf);
}
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index 49a3bc8..217c1d5 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -383,10 +383,15 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
self->priv->pixbuf_height = gdk_pixbuf_get_height (src_pixbuf);
width = self->priv->pixbuf_width;
height = self->priv->pixbuf_height;
- if (scale_keeping_ratio (&width, &height, max_size, max_size, FALSE))
+ if (scale_keeping_ratio (&width, &height, max_size, max_size, FALSE)) {
self->priv->tmp_pixbuf = _gdk_pixbuf_scale_simple_safe (src_pixbuf, width, height, GDK_INTERP_BILINEAR);
- else
- self->priv->tmp_pixbuf = gdk_pixbuf_copy (src_pixbuf);
+ }
+ else {
+ self->priv->tmp_pixbuf = src_pixbuf;
+ src_pixbuf = NULL;
+ }
+
+ _g_object_unref (src_pixbuf);
self->priv->unit = eel_gconf_get_enum (PREF_ROTATE_UNIT, GTH_TYPE_UNIT, GTH_UNIT_PERCENTAGE);
self->priv->builder = _gtk_builder_new_from_file ("rotate-options.ui", "file_tools");
diff --git a/extensions/file_tools/gth-file-tool-sharpen.c b/extensions/file_tools/gth-file-tool-sharpen.c
index 11ec0e2..012ff5b 100644
--- a/extensions/file_tools/gth-file-tool-sharpen.c
+++ b/extensions/file_tools/gth-file-tool-sharpen.c
@@ -264,7 +264,6 @@ gth_file_tool_sharpen_get_options (GthFileTool *base)
if (self->priv->src_pixbuf == NULL)
return NULL;
- self->priv->src_pixbuf = g_object_ref (self->priv->src_pixbuf);
self->priv->dest_pixbuf = NULL;
self->priv->builder = _gtk_builder_new_from_file ("sharpen-options.ui", "file_tools");
diff --git a/extensions/file_tools/gth-image-rotator.c b/extensions/file_tools/gth-image-rotator.c
index fcb1780..9b07bf3 100644
--- a/extensions/file_tools/gth-image-rotator.c
+++ b/extensions/file_tools/gth-image-rotator.c
@@ -125,10 +125,15 @@ update_image_surface (GthImageRotator *self)
height = self->priv->original_height;
gtk_widget_get_allocation (GTK_WIDGET (self->priv->viewer), &allocation);
max_size = MIN (allocation.width, allocation.height) / 1.2;
- if (scale_keeping_ratio (&width, &height, max_size, max_size, FALSE))
+ if (scale_keeping_ratio (&width, &height, max_size, max_size, FALSE)) {
tmp_pixbuf = _gdk_pixbuf_scale_simple_safe (src_pixbuf, width, height, GDK_INTERP_BILINEAR);
- else
- tmp_pixbuf = gdk_pixbuf_copy (src_pixbuf);
+ }
+ else {
+ tmp_pixbuf = src_pixbuf;
+ src_pixbuf = NULL;
+ }
+
+ _g_object_unref (src_pixbuf);
self->priv->preview_zoom = (double) width / self->priv->original_width;
diff --git a/extensions/image_print/actions.c b/extensions/image_print/actions.c
index 5bb3472..4a56017 100644
--- a/extensions/image_print/actions.c
+++ b/extensions/image_print/actions.c
@@ -43,7 +43,6 @@ gth_browser_activate_action_file_print (GtkAction *action,
GError *error = NULL;
current_image = NULL;
-
viewer_page = gth_browser_get_viewer_page (browser);
if ((gth_main_extension_is_active ("image_viewer"))
&& (viewer_page != NULL)
@@ -54,12 +53,13 @@ gth_browser_activate_action_file_print (GtkAction *action,
viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
current_image = gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (viewer));
}
-
print_job = gth_image_print_job_new (file_list,
gth_browser_get_current_file (browser),
current_image,
g_file_info_get_display_name (gth_browser_get_location_data (browser)->info),
&error);
+ _g_object_unref (current_image);
+
if (print_job != NULL)
gth_image_print_job_run (print_job,
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
diff --git a/extensions/image_viewer/gth-image-histogram.c b/extensions/image_viewer/gth-image-histogram.c
index 7ab6e7f..e589d07 100644
--- a/extensions/image_viewer/gth-image-histogram.c
+++ b/extensions/image_viewer/gth-image-histogram.c
@@ -65,8 +65,10 @@ gth_image_histogram_real_set_file (GthPropertyView *base,
return;
}
- pixbuf = gth_image_viewer_page_get_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page));
+ pixbuf = gth_image_viewer_page_get_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page)); /* FIXME: use the cairo_surface here */
gth_histogram_calculate (self->priv->histogram, pixbuf);
+
+ g_object_unref (pixbuf);
}
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index c6567a2..056cd18 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -294,6 +294,8 @@ image_preloader_requested_ready_cb (GthImagePreloader *preloader,
GError *error,
GthImageViewerPage *self)
{
+ GdkPixbuf *pixbuf;
+
if (! _g_file_equal (requested->file, self->priv->file_data->file))
return;
@@ -310,10 +312,11 @@ image_preloader_requested_ready_cb (GthImagePreloader *preloader,
if (self->priv->shrink_wrap)
gth_image_viewer_page_shrink_wrap (self, TRUE);
gth_image_history_clear (self->priv->history);
- gth_image_history_add_image (self->priv->history,
- gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (self->priv->viewer)),
- FALSE);
+ pixbuf = gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (self->priv->viewer));
+ gth_image_history_add_image (self->priv->history, pixbuf, FALSE);
gth_image_viewer_page_file_loaded (self, TRUE);
+
+ _g_object_unref (pixbuf);
}
@@ -326,6 +329,8 @@ image_preloader_original_size_ready_cb (GthImagePreloader *preloader,
GError *error,
GthImageViewerPage *self)
{
+ GdkPixbuf *pixbuf;
+
if (! _g_file_equal (requested->file, self->priv->file_data->file))
return;
@@ -337,9 +342,10 @@ image_preloader_original_size_ready_cb (GthImagePreloader *preloader,
original_width,
original_height);
gth_image_history_clear (self->priv->history);
- gth_image_history_add_image (self->priv->history,
- gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (self->priv->viewer)),
- FALSE);
+ pixbuf = gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (self->priv->viewer));
+ gth_image_history_add_image (self->priv->history, pixbuf, FALSE);
+
+ _g_object_unref (pixbuf);
}
@@ -1015,6 +1021,7 @@ _gth_image_viewer_page_real_save (GthViewerPage *base,
GthImageViewerPage *self;
SaveData *data;
GthFileData *current_file;
+ GdkPixbuf *pixbuf;
self = (GthImageViewerPage *) base;
@@ -1032,12 +1039,15 @@ _gth_image_viewer_page_real_save (GthViewerPage *base,
gth_file_data_set_file (current_file, file);
g_file_info_set_attribute_boolean (current_file->info, "gth::file::is-modified", FALSE);
- _gdk_pixbuf_save_async (gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (self->priv->viewer)),
+ pixbuf = gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (self->priv->viewer));
+ _gdk_pixbuf_save_async (pixbuf,
current_file,
mime_type,
TRUE,
image_saved_cb,
data);
+
+ _g_object_unref (pixbuf);
}
diff --git a/extensions/red_eye_removal/gth-file-tool-red-eye.c b/extensions/red_eye_removal/gth-file-tool-red-eye.c
index 9a1fc44..0418ea8 100644
--- a/extensions/red_eye_removal/gth-file-tool-red-eye.c
+++ b/extensions/red_eye_removal/gth-file-tool-red-eye.c
@@ -328,14 +328,12 @@ selector_selected_cb (GthImageSelector *selector,
{
GtkWidget *window;
GtkWidget *viewer_page;
- GdkPixbuf *old_pixbuf;
GdkPixbuf *new_pixbuf;
window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
- old_pixbuf = gth_image_viewer_page_get_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page));
- new_pixbuf = gdk_pixbuf_copy (old_pixbuf);
+ new_pixbuf = gth_image_viewer_page_get_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page));
init_is_red (self, new_pixbuf);
if (fix_redeye (new_pixbuf, self->priv->is_red, x, y)) {
gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), new_pixbuf, TRUE);
diff --git a/gthumb/gth-image-viewer.c b/gthumb/gth-image-viewer.c
index 91f9352..739b3e8 100644
--- a/gthumb/gth-image-viewer.c
+++ b/gthumb/gth-image-viewer.c
@@ -1845,16 +1845,7 @@ gth_image_viewer_get_original_size (GthImageViewer *self,
gboolean
gth_image_viewer_get_has_alpha (GthImageViewer *self)
{
- GdkPixbuf *pixbuf;
-
- g_return_val_if_fail (self != NULL, FALSE);
-
- /* FIXME */
- pixbuf = gth_image_viewer_get_current_pixbuf (self);
- if (pixbuf != NULL)
- return gdk_pixbuf_get_has_alpha (pixbuf);
-
- return FALSE;
+ return TRUE; /* FIXME */
}
@@ -1870,7 +1861,7 @@ gth_image_viewer_get_current_pixbuf (GthImageViewer *self)
return _gdk_pixbuf_new_from_cairo_surface (self->priv->surface);
if (self->priv->iter != NULL)
- return gdk_pixbuf_animation_iter_get_pixbuf (self->priv->iter);
+ return gdk_pixbuf_copy (gdk_pixbuf_animation_iter_get_pixbuf (self->priv->iter));
return NULL;
}
@@ -2429,10 +2420,6 @@ gth_image_viewer_paint (GthImageViewer *self,
cairo_scale (cr, zoom_level, zoom_level);
- /* FIXME: paint the background for images with a transparency */
-
- /* g_print ("src: (%d, %d) -- dest: (%d, %d) [%d, %d]\n", src_x, src_y, dest_x, dest_y, width, height); */
-
cairo_set_source_surface (cr, surface, dest_dx - src_dx, dest_dy - src_dy);
cairo_pattern_set_filter (cairo_get_source (cr), filter);
cairo_rectangle (cr, dest_dx, dest_dy, dwidth, dheight);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]