[perl-Gtk2] Fix leak in Gtk2::Gdk::Drawable->get_image()



commit 98e64cb594aa7fe4e989ef4e9cf10f6bf0abd1fe
Author: Kevin Ryde <user42 zip com au>
Date:   Wed Nov 17 11:22:59 2010 +1100

    Fix leak in Gtk2::Gdk::Drawable->get_image()
    
    Use _noinc to avoid reference leak on returned image.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621710

 t/GdkDrawable.t   |   18 ++++++++++++------
 xs/GdkDrawable.xs |    5 +++--
 2 files changed, 15 insertions(+), 8 deletions(-)
---
diff --git a/t/GdkDrawable.t b/t/GdkDrawable.t
index 6bfc8f1..1d8e409 100644
--- a/t/GdkDrawable.t
+++ b/t/GdkDrawable.t
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 use strict;
-use Gtk2::TestHelper tests => 11;
+use Gtk2::TestHelper tests => 12;
 
 # $Id$
 
@@ -78,14 +78,17 @@ $win -> draw_layout_with_colors($gc, 10, 10, $layout, $black, $black);
 $win -> draw_layout_with_colors($gc, 10, 10, $layout, undef,  $black);
 $win -> draw_drawable($gc, $win, 5, 5, 5, 5, 10, 10);
 
-my $image = $win -> get_image(5, 5, 10, 10);
-
 SKIP: {
-  skip("get_image returned undef, skipping draw_image", 1)
+  my $image = $win -> get_image(5, 5, 10, 10);
+  skip("get_image returned undef, skipping draw_image", 2)
     unless (defined($image));
 
   isa_ok($image, "Gtk2::Gdk::Image");
   $win -> draw_image($gc, $image, 0, 0, 0, 0, 50, 50);
+
+  require Scalar::Util;
+  Scalar::Util::weaken ($image);
+  is ($image, undef, 'get_image() resulting image destroyed when unreferenced');
 }
 
 SKIP: {
@@ -101,8 +104,11 @@ SKIP: {
 SKIP: {
   skip("copy_to_image is new in 2.4", 1)
     unless Gtk2->CHECK_VERSION (2, 4, 0);
+  my $existing_image = $win -> get_image(5, 5, 10, 10);
+  skip("get_image returned undef, skipping draw_image", 2)
+    unless (defined($existing_image));
 
-  my $image = $win -> copy_to_image($image, 0, 0, 0, 0, 50, 50);
+  my $image = $win -> copy_to_image($existing_image, 0, 0, 0, 0, 50, 50);
 
   skip ("copy_to_image returned undef", 1)
     unless (defined($image));
@@ -112,5 +118,5 @@ SKIP: {
 
 __END__
 
-Copyright (C) 2003-2009 by the gtk2-perl team (see the file AUTHORS for the
+Copyright (C) 2003-2010 by the gtk2-perl team (see the file AUTHORS for the
 full list).  See LICENSE for more information.
diff --git a/xs/GdkDrawable.xs b/xs/GdkDrawable.xs
index c6b8d71..445bdcb 100644
--- a/xs/GdkDrawable.xs
+++ b/xs/GdkDrawable.xs
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003-2005, 2009 by the gtk2-perl team (see the file AUTHORS)
+ * Copyright (c) 2003-2005, 2009, 2010 by the gtk2-perl team (see the file AUTHORS)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -327,7 +327,8 @@ gdk_draw_layout_with_colors (drawable, gc, x, y, layout, foreground, background)
 MODULE = Gtk2::Gdk::Drawable	PACKAGE = Gtk2::Gdk::Drawable	PREFIX = gdk_drawable_
 
  ## GdkImage* gdk_drawable_get_image (GdkDrawable *drawable, gint x, gint y, gint width, gint height)
-GdkImage*
+ ## The return is a non-floating refcount==1, hence _noinc.
+GdkImage_noinc *
 gdk_drawable_get_image (drawable, x, y, width, height)
 	GdkDrawable *drawable
 	gint x



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]