From 444ba0ca9ffd204baa3a2ad18ddd653485048204 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Sat, 13 Feb 2010 11:36:11 +0000 Subject: [PATCH] 2010-02-13 12:36 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/vm/strapi.c ! fixed hb_[w]strunshare() functions to always clone writable buffers shared by two or more different objects or items. --- harbour/ChangeLog | 5 +++++ harbour/src/vm/strapi.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2a5c9fcebc..6f502b18ea 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,11 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-02-13 12:36 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/vm/strapi.c + ! fixed hb_[w]strunshare() functions to always clone writable + buffers shared by two or more different objects or items. + 2010-02-13 11:42 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/wapi_winbase.c + Added WAPI_GETLONGPATHNAME() (same code as the short version) diff --git a/harbour/src/vm/strapi.c b/harbour/src/vm/strapi.c index 45088bd278..5f094c2486 100644 --- a/harbour/src/vm/strapi.c +++ b/harbour/src/vm/strapi.c @@ -159,12 +159,15 @@ HB_WCHAR * hb_wstrunshare( void ** phStr, const HB_WCHAR * pStr, HB_SIZE ulLen ) if( pStr == NULL || phStr == NULL || *phStr == NULL ) return NULL; - if( *phStr == ( void * ) s_szConstStr && ulLen > 0 ) + if( ulLen > 0 && + ( *phStr == ( void * ) s_szConstStr || hb_xRefCount( *phStr ) > 1 ) ) { HB_WCHAR * pszDest = ( HB_WCHAR * ) hb_xgrab( ( ulLen + 1 ) * sizeof( HB_WCHAR ) ); memcpy( pszDest, pStr, ulLen * sizeof( HB_WCHAR ) ); pszDest[ ulLen ] = 0; + if( *phStr != ( void * ) s_szConstStr ) + hb_xRefDec( *phStr ); * phStr = ( void * ) pszDest; return pszDest; @@ -180,11 +183,14 @@ char * hb_strunshare( void ** phStr, const char * pStr, HB_SIZE ulLen ) if( pStr == NULL || phStr == NULL || *phStr == NULL ) return NULL; - if( *phStr == ( void * ) s_szConstStr && ulLen > 0 ) + if( ulLen > 0 && + ( *phStr == ( void * ) s_szConstStr || hb_xRefCount( *phStr ) > 1 ) ) { char * pszDest = ( char * ) hb_xgrab( ( ulLen + 1 ) * sizeof( char ) ); memcpy( pszDest, pStr, ulLen * sizeof( char ) ); pszDest[ ulLen ] = 0; + if( *phStr != ( void * ) s_szConstStr ) + hb_xRefDec( *phStr ); * phStr = ( void * ) pszDest; return pszDest;