Branch: Tag:

2010-07-31

2010-07-31 23:35:36 by Marcus Comstedt <marcus@mc.pp.se>

Fixed a segfault in GTK2.GdkImage()->set().

Previously, g_object_unref(THIS->obj) was called before the call to
gdkimage_from_pikeimage() to make sure the old object was unreffed in
the case that the latter function threw an error. This was all good
and well, except for the fact that THIS->obj was actually _used_ by
gdkimage_from_pikeimage(), which turned out to be a bit difficult when
said object was already freed.

The logic is now changed so that gdkimage_from_pikeimage() is
responsible for unreffing the object as needed, and also for making
sure that THIS->obj has an appropriate value if and when an exception
is thrown (like for example, not the old unreffed object).

Rev: src/post_modules/GTK2/pgtk.h:1.21
Rev: src/post_modules/GTK2/source/gdkimage.pre:1.8
Rev: src/post_modules/GTK2/source/support.c:1.24

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: support.c,v 1.23 2010/02/09 17:53:42 ldillon Exp $ + || $Id: support.c,v 1.24 2010/07/31 23:35:36 marcus Exp $   */      #include <version.h>
86:    return 1;   }    - GdkImage *gdkimage_from_pikeimage(struct object *img, int fast, GdkImage *i) { + GdkImage *gdkimage_from_pikeimage(struct object *img, int fast, GObject **pi) { +  GdkImage *i;    GdkColormap *col=gdk_colormap_get_system();    GdkVisual *vis=gdk_visual_get_system();    struct image *img_data;
103:       if (x==0 || y==0)    Pike_error("Size of image must be > 0x0\n"); -  if (i) { -  if ((i->width!=x) || (i->height!=y)) { -  gdk_image_destroy((void *)i); +  if (pi) { +  i = *pi; +  if (i != NULL && ((i->width!=x) || (i->height!=y))) { +  g_object_unref(i); +  gdk_image_destroy(i);    i=NULL;    } -  } +  } else +  i=NULL;    if (!i) {    PFTIME("Create");    i=(void *)gdk_image_new(fast,vis,x,y);    } -  +  if (pi) +  *pi = i;       if (!i)    Pike_error("Failed to create gdkimage\n");