Re: Memory management with GdkPixbuf



On Tue, 2003-09-30 at 12:04, Luis M. Fuentes wrote:
{
gint  nrws , nysz ;
if    ( g_file_test (path, G_FILE_TEST_EXISTS) != TRUE ) return false ;
GdkPixbuf         *wPixbuf = gdk_pixbuf_new_from_file ( path , NULL ) ;
if ( wPixbuf == NULL )        return false ;  
nrws = gdk_pixbuf_get_rowstride (wPixbuf) ;
nysz = gdk_pixbuf_get_height (wPixbuf) ;
if    ( nrws != rws || nysz != ysz )
      {
              xsz = gdk_pixbuf_get_width (wPixbuf) ;
              ysz = nysz ;            rws = nrws ;
              nch = gdk_pixbuf_get_n_channels (wPixbuf) ;
              bps = gdk_pixbuf_get_bits_per_sample (wPixbuf) ;
              imgbsz = (glong)(rws) * ysz ;
              if      ( pixBuf != NULL )      g_free((gpointer)(pixBuf)) ;
      }
pixBuf = (guchar*) g_memdup ( 
(gconstpointer)gdk_pixbuf_get_pixels(wPixbuf),imgbsz) ;

This will leak, because pixBuf is only freed when the width and height
are not the same. You need to move the
if (pixBuf != NULL) g_free ((gpointer) (pixBuf)); out of the
if (nrws != rws || nysz != ysz) statements.

And as an aside g_free will work if you pass NULL, so you don't need to
check if pixBuf != NULL before calling it.

iain
-- 
But TV says "Surface irony" is funny . . . don't you watch Saturday
Night Live, man?




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