[GB.GTK]
* BUG: Fix memory leak when loading images without alpha channel. git-svn-id: svn://localhost/gambas/trunk@6071 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
ce4ac176ef
commit
e28bd14ae3
3 changed files with 27 additions and 14 deletions
|
@ -531,6 +531,7 @@ static void style_panel(int x, int y, int w, int h, int border, int state)
|
|||
}
|
||||
|
||||
gt_draw_border(_cr, style, get_state(state), border, col, x, y, w, h);
|
||||
|
||||
#else
|
||||
GtkShadowType shadow;
|
||||
GtkStateType st = get_state(state);
|
||||
|
|
|
@ -35,13 +35,14 @@ gPicture
|
|||
|
||||
#define LOAD_INC 65536L
|
||||
|
||||
static bool pixbufFromMemory(GdkPixbuf **pixbuf, char *addr, unsigned int len, bool *trans)
|
||||
static bool pixbufFromMemory(GdkPixbuf **ppixbuf, char *addr, unsigned int len, bool *trans)
|
||||
{
|
||||
GdkPixbufLoader* loader;
|
||||
GdkPixbufLoader *loader;
|
||||
GdkPixbuf *pixbuf;
|
||||
GError *error = NULL;
|
||||
gsize size;
|
||||
|
||||
*pixbuf = 0;
|
||||
*ppixbuf = 0;
|
||||
|
||||
loader = gdk_pixbuf_loader_new();
|
||||
|
||||
|
@ -63,23 +64,24 @@ static bool pixbufFromMemory(GdkPixbuf **pixbuf, char *addr, unsigned int len, b
|
|||
goto __ERROR;
|
||||
}
|
||||
|
||||
(*pixbuf) = gdk_pixbuf_loader_get_pixbuf(loader);
|
||||
g_object_ref(G_OBJECT(*pixbuf));
|
||||
pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
|
||||
g_object_ref(pixbuf);
|
||||
|
||||
if (gdk_pixbuf_get_n_channels(*pixbuf) == 3)
|
||||
if (gdk_pixbuf_get_n_channels(pixbuf) == 3)
|
||||
{
|
||||
// Rowstride breaks gb.image (it is rounded up so that a line is always a four bytes multiple).
|
||||
GdkPixbuf *aimg;
|
||||
aimg = gdk_pixbuf_add_alpha(*pixbuf, FALSE, 0, 0, 0);
|
||||
g_object_unref(G_OBJECT(*pixbuf));
|
||||
g_object_ref(G_OBJECT(aimg));
|
||||
*pixbuf = aimg;
|
||||
aimg = gdk_pixbuf_add_alpha(pixbuf, FALSE, 0, 0, 0);
|
||||
g_object_unref(pixbuf);
|
||||
pixbuf = aimg;
|
||||
*trans = false;
|
||||
}
|
||||
else
|
||||
*trans = true;
|
||||
|
||||
g_object_unref(G_OBJECT(loader));
|
||||
|
||||
*ppixbuf = pixbuf;
|
||||
return true;
|
||||
|
||||
__ERROR:
|
||||
|
@ -104,6 +106,7 @@ void gPicture::initialize()
|
|||
|
||||
gPicture::gPicture() : gShare()
|
||||
{
|
||||
//fprintf(stderr, "gPicture(): %p\n", this);
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
@ -151,6 +154,7 @@ void gPicture::createMask(bool opaque)
|
|||
|
||||
gPicture::gPicture(gPictureType type, int w, int h, bool trans) : gShare()
|
||||
{
|
||||
//fprintf(stderr, "gPicture(): %p: %d %d %d %d\n", this, type, w, h, trans);
|
||||
initialize();
|
||||
|
||||
_transparent = trans;
|
||||
|
@ -188,6 +192,7 @@ gPicture::gPicture(gPictureType type, int w, int h, bool trans) : gShare()
|
|||
|
||||
gPicture::gPicture(GdkPixbuf *image, bool trans) : gShare()
|
||||
{
|
||||
//fprintf(stderr, "gPicture(image): %p: %p %d\n", this, image, trans);
|
||||
initialize();
|
||||
if (!image)
|
||||
return;
|
||||
|
@ -241,6 +246,7 @@ gPicture::gPicture(GdkPixmap *pix) : gShare()
|
|||
|
||||
gPicture::~gPicture()
|
||||
{
|
||||
//fprintf(stderr, "~gPicture: %p\n", this);
|
||||
clear();
|
||||
}
|
||||
|
||||
|
@ -365,6 +371,8 @@ GdkPixmap *gPicture::getPixmap()
|
|||
if (_type != PIXBUF)
|
||||
getPixbuf();
|
||||
|
||||
if (pixmap)
|
||||
g_object_unref(G_OBJECT(pixmap));
|
||||
if (mask)
|
||||
g_object_unref(G_OBJECT(mask));
|
||||
|
||||
|
@ -391,7 +399,10 @@ gPicture *gPicture::fromMemory(char *addr, unsigned int len)
|
|||
if (!pixbufFromMemory(&pixbuf, addr, len, &trans))
|
||||
return 0;
|
||||
else
|
||||
return new gPicture(pixbuf);
|
||||
{
|
||||
gPicture *pic = new gPicture(pixbuf);
|
||||
return pic;
|
||||
}
|
||||
}
|
||||
|
||||
gPicture *gPicture::fromData(const char *data, int width, int height)
|
||||
|
@ -627,6 +638,7 @@ gPicture* gPicture::fromNamedIcon(const char *name, int len)
|
|||
void gPicture::clear()
|
||||
{
|
||||
//fprintf(stderr, "gPicture::clear: %p (%d %d) pixmap = %p pixbuf = %p\n", this, _width, _height, pixmap, pixbuf);
|
||||
|
||||
_width = 0;
|
||||
_height = 0;
|
||||
_type = VOID;
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
|
||||
#include "gtag.h"
|
||||
|
||||
//#define DEBUG_ME
|
||||
//#define DEBUG_SHARE 1
|
||||
|
||||
#ifdef DEBUG_ME
|
||||
#ifdef DEBUG_SHARE
|
||||
|
||||
class gShare
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue