More binding friendly API for SugarPreview.

Fix a leak.
This commit is contained in:
Marco Pesenti Gritti 2007-11-14 19:59:11 +01:00
parent cd0e6aa101
commit 411879e9de
3 changed files with 20 additions and 5 deletions

2
NEWS
View File

@ -1,3 +1,5 @@
* #4768 Fix memory leak when switching between activities. (marco)
Snapshot 9d28557bbd Snapshot 9d28557bbd
* Fix randr. (marco) * Fix randr. (marco)

View File

@ -39,16 +39,22 @@ sugar_preview_get_pixbuf(SugarPreview *preview)
{ {
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
if (preview->pixbuf != NULL) {
return preview->pixbuf;
}
if (preview->image == NULL) { if (preview->image == NULL) {
return NULL; return NULL;
} }
pixbuf = gdk_pixbuf_get_from_image(NULL, preview->image, NULL, preview->pixbuf = gdk_pixbuf_get_from_image(NULL, preview->image, NULL,
0, 0, 0, 0, 0, 0, 0, 0,
preview->image->width, preview->image->width,
preview->image->height); preview->image->height);
g_object_unref(G_OBJECT(preview->image));
preview->image = NULL;
return pixbuf; return preview->pixbuf;
} }
void void
@ -58,6 +64,10 @@ sugar_preview_clear(SugarPreview *preview)
g_object_unref(G_OBJECT(preview->image)); g_object_unref(G_OBJECT(preview->image));
preview->image = NULL; preview->image = NULL;
} }
if (preview->pixbuf != NULL) {
g_object_unref(G_OBJECT(preview->pixbuf));
preview->pixbuf = NULL;
}
} }
void void
@ -104,4 +114,5 @@ static void
sugar_preview_init(SugarPreview *preview) sugar_preview_init(SugarPreview *preview)
{ {
preview->image = NULL; preview->image = NULL;
preview->pixbuf = NULL;
} }

View File

@ -38,6 +38,8 @@ struct _SugarPreview {
GObject base_instance; GObject base_instance;
GdkImage *image; GdkImage *image;
GdkPixbuf *pixbuf;
int width; int width;
int height; int height;
}; };