FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Antonio: Memory Leak in DipWrite
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM

Antonio: Memory Leak in DipWrite

Posted: Tue Nov 12, 2013 03:43 PM
Antonio, i found, that in this function pDip should released with
Code (fw): Select all Collapse
hb_xfree( ( char * ) pDib );
on 3 positions. I write 1000 BMPs and then the computer-Memory are full in my case. I searched for the reason and found this.

Code (fw): Select all Collapse
BOOL DibWrite( LPSTR szFileName, HGLOBAL hDIB )
{

   long lSize;
   char * pDib;
   int hBmp;

   pDib = DibToStr( hDIB, &lSize );

   #ifndef UNICODE
   if( ( hBmp = _lcreat( szFileName, 0 ) ) != HFILE_ERROR )
   {
      _hwrite( hBmp, ( const char * ) pDib, lSize );
      _lclose( hBmp );
      GlobalUnlock( hDIB );
    hb_xfree( ( char * ) pDib );
      return TRUE;
   }
   #else
   if( ( hBmp = hb_fsCreate( ( unsigned char * ) szFileName, 0 ) ) != ( int ) INVALID_HANDLE_VALUE )
   {
      hb_fsWriteLarge( hBmp, ( unsigned char * ) pDib, lSize );
      hb_fsClose( hBmp );
      GlobalUnlock( hDIB );
    hb_xfree( ( char * ) pDib );
      return TRUE;
   }
   #endif
   else
   {
      GlobalUnlock( hDIB );
    hb_xfree( ( char * ) pDib );
      return FALSE;
   }
}
Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Antonio: Memory Leak in DipWrite

Posted: Tue Nov 12, 2013 06:03 PM

Günther,

You are totally right. Many thanks! :-)

Included for next FWH build.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM

Re: Antonio: Memory Leak in DipWrite

Posted: Wed Nov 13, 2013 10:29 AM

Antonio, all is ok now. Maybe you should check all hb_xalloc() and hb_xgrab() for corresponding hb_xfree(). Specially in C-functions, which returns only a pointer and this pointer are to released in the calling function.

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Antonio: Memory Leak in DipWrite

Posted: Wed Nov 13, 2013 11:10 AM

Günther,

I constantly do it, though sometimes we may miss a case, like this one. thanks,

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion