Page 3 of 4

HMG_Upper() function causes a memory leak

Posted: Wed Oct 05, 2016 1:04 pm
by Pablo César
Hi Claudio,

I do not know well if this would helps to you in HMG_UPPER case:
Screen11.png
Screen11.png (28.29 KiB) Viewed 4591 times
Or if these C functions are acting under ANSI mode with UTF8 because cdp parameter.

Please check: hb_cdpnDupUpper(), hb_cdpnDupLower(), hb_cdpnDup2Upper(), hb_cdpnDup2Lower() or hb_strUpper() and hb_strLower()

ADDED LATER:
These other C functions: hb_strncpy(), hb_strncpyLower(), hb_strncpyUpper()

Re: HMG_Upper() function causes a memory leak

Posted: Wed Oct 05, 2016 1:50 pm
by srvet_claudio
Pablo César wrote:Hi Claudio,

I do not know well if this would helps to you in HMG_UPPER case:
Screen11.png
Or if these C functions are acting under ANSI mode with UTF8 because cdp parameter.

Please check: hb_cdpnDupUpper(), hb_cdpnDupLower(), hb_cdpnDup2Upper(), hb_cdpnDup2Lower() or hb_strUpper() and hb_strLower()

ADDED LATER:
These other C functions: hb_strncpy(), hb_strncpyLower(), hb_strncpyUpper()
Thanks Pablo.
I fixed the problem in hmg_upper and hmg_lower

Re: HMG_Upper() function causes a memory leak

Posted: Wed Jan 18, 2017 8:21 pm
by KDJ
srvet_claudio wrote: Wed Oct 05, 2016 1:50 pm I fixed the problem in hmg_upper and hmg_lower
Hi Claudio

Memory leaks are a serious problem in HMG.
I do not know how you solved it in hmg_upper and hmg_lower.
But I noticed that this occurs in all C functions, that uses HMG_parc, HMG_retc and HMG_storc macros.
So I checked this more accurately, and it seems to me that I was able to locate the bug.
HMG_UNICODE.h wrote:

Code: Select all

   #define HMG_CHAR_TO_WCHAR(c)     ((c != NULL) ? hb_osStrU16Encode(c) : NULL)  // return WCHAR
      #define HMG_parc(n)            HMG_CHAR_TO_WCHAR (hb_parc(n))
      #define HMG_parvc(n,i)         HMG_CHAR_TO_WCHAR (hb_parvc(n,i))
      #define HMG_arrayGetCPtr(a,n)  HMG_CHAR_TO_WCHAR (hb_arrayGetCPtr(a,n))

   #define HMG_WCHAR_TO_CHAR(c)      hb_osStrU16Decode(c)                       // return CHAR
      #define HMG_retc(c)            hb_retc    (HMG_WCHAR_TO_CHAR(c))
      #define HMG_storc(c,i)         hb_storc   (HMG_WCHAR_TO_CHAR(c),i)
      #define HMG_storvc(c,l,n)      hb_storvc  (HMG_WCHAR_TO_CHAR(c),l,n) 
      #define HMG_retclen(c,l)       hb_retclen (HMG_WCHAR_TO_CHAR(c),l)
      #define HMG_retc_buffer(c)     hb_retc_buffer (HMG_WCHAR_TO_CHAR(c))

      #define HMG_itemPutC(p, c)            hb_itemPutC      (p, HMG_WCHAR_TO_CHAR(c))
      #define HMG_itemPutCL(p, c, l)        hb_itemPutCL     (p, HMG_WCHAR_TO_CHAR(c), l)
      #define HMG_itemPutCConst(p, c)       hb_itemPutCConst (p, HMG_WCHAR_TO_CHAR(c))
      #define HMG_itemPutCLConst(p, c, l)   hb_itemPutCLConst(p, HMG_WCHAR_TO_CHAR(c), l)
      #define HMG_itemPutCPtr(p, c)         hb_itemPutCPtr   (p, HMG_WCHAR_TO_CHAR(c))
      #define HMG_itemPutCLPtr(p, c, l)     hb_itemPutCLPtr  (p, HMG_WCHAR_TO_CHAR(c), l)
set.c (in Harbour) wrote:

Code: Select all

HB_WCHAR * hb_osStrU16Encode( const char * pszName )
{
   if( hb_vmIsReady() )
   {
      PHB_CODEPAGE cdp = hb_vmCDP();
      if( cdp )
      {
         HB_SIZE nLen, nSize;
         HB_WCHAR * pszBufferW;

         nLen = strlen( pszName );
         nSize = hb_cdpStrAsU16Len( cdp, pszName, nLen, 0 );
         pszBufferW = ( HB_WCHAR * ) hb_xgrab( ( nSize + 1 ) * sizeof( HB_WCHAR ) );
         hb_cdpStrToU16( cdp, HB_CDP_ENDIAN_NATIVE, pszName, nLen, pszBufferW, nSize + 1 );
         return pszBufferW;
      }
   }

   return hb_mbtowc( pszName ); /* No HVM stack */
}
Note that the buffer is initialized by using hb_xgrab function:
pszBufferW = ( HB_WCHAR * ) hb_xgrab( ( nSize + 1 ) * sizeof( HB_WCHAR ) );
and it is nowhere released by hb_xfree.

Re: HMG_Upper() function causes a memory leak

Posted: Thu Jan 19, 2017 12:29 am
by srvet_claudio
Many thanks for the info. I will fixed

HMG_Upper() function causes a memory leak

Posted: Thu Jan 19, 2017 12:41 am
by Pablo César
Congratulations guys.

This is teamwork, pure altruism and a lot of fellowship.

It is not enough to just criticize.
The guy, detects, looks for a possible solution and informs.
Perfect work of the two colleagues.

I love this kind of things. Congratulations Claudio and Krzysztof.

We are all winners when there is competence on both sides and a lot of humility.

I want to learn a lot from you.

Many thanks to both.

My best regards

Re: HMG_Upper() function causes a memory leak

Posted: Thu Jan 19, 2017 1:25 am
by quartz565
+1

Re: HMG_Upper() function causes a memory leak

Posted: Thu Jan 19, 2017 7:12 am
by bpd2000
Pablo César wrote: Thu Jan 19, 2017 12:41 am
Congratulations guys.
This is teamwork, pure altruism and a lot of fellowship.
Many thanks to both.
My best regards
+1

Re: HMG_Upper() function causes a memory leak

Posted: Thu Jan 19, 2017 8:22 am
by serge_girard
+10

Re: HMG_Upper() function causes a memory leak

Posted: Thu Jan 19, 2017 9:57 am
by Anand
Pablo César wrote: Thu Jan 19, 2017 12:41 am Congratulations guys.

This is teamwork, pure altruism and a lot of fellowship.
Rightly said. It is the base of HMG. Congratulations to all who work hard for it.

Regards,

Anand

Re: HMG_Upper() function causes a memory leak

Posted: Thu Jan 19, 2017 11:50 am
by quartz565
serge_girard wrote: Thu Jan 19, 2017 8:22 am+10
+1 :D