HMG_Upper() function causes a memory leak

Moderator: Rathinagiri

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 182 times

HMG_Upper() function causes a memory leak

Post 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 2193 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()
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
srvet_claudio
Posts: 2044
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 35 times
Been thanked: 153 times
Contact:

Post 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
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

KDJ
Posts: 242
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 291 times

Post 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.

User avatar
srvet_claudio
Posts: 2044
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 35 times
Been thanked: 153 times
Contact:

Post by srvet_claudio »

Many thanks for the info. I will fixed
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 182 times

Post 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
Last edited by Pablo César on Thu Jan 19, 2017 1:19 pm, edited 1 time in total.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
quartz565
Posts: 590
Joined: Mon Oct 01, 2012 12:37 pm
Location: Thessaloniki, Greece
Has thanked: 195 times
Been thanked: 23 times
Contact:

Post by quartz565 »

+1
Best Regards,
Nikos.

os: Windows Server 2012 - 64
hw: HP Server E5606, 2.13GHz, 8.00 GB - Intel Xeon CPU

User avatar
bpd2000
Posts: 1139
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 233 times
Been thanked: 136 times

Post 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
BPD
Convert Dream into Reality through HMG

User avatar
serge_girard
Posts: 2484
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 781 times
Been thanked: 147 times
Contact:

Post by serge_girard »

+10

User avatar
Anand
Posts: 481
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 184 times
Been thanked: 69 times

Post 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
Image

User avatar
quartz565
Posts: 590
Joined: Mon Oct 01, 2012 12:37 pm
Location: Thessaloniki, Greece
Has thanked: 195 times
Been thanked: 23 times
Contact:

Post by quartz565 »

serge_girard wrote:
Thu Jan 19, 2017 8:22 am
+10
+1 :D
Best Regards,
Nikos.

os: Windows Server 2012 - 64
hw: HP Server E5606, 2.13GHz, 8.00 GB - Intel Xeon CPU

Post Reply