dbTalk Databases Forums  

Heap block modified past requested size of 130

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Heap block modified past requested size of 130 in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Blaz Ziherl
 
Posts: n/a

Default Heap block modified past requested size of 130 - 01-21-2005 , 07:09 PM






Hi,

This is probably a bit more C++ oriented question, but:

I have my own custom transformation, which crashes whenever I want to clear
buffer with larger piece of text ("delete (pstrBuffer);"), saying:

"Heap block at xxx modified at xxx past requested size of 130"

I know I am obviously trying to release more memory than I am allowed to,
but since I have declared problematic "pstrBuffer = (LPSTR)new char[500];",
why can't I delete all 500 chars? I don't get it.

This is my piece of code, if anyone could help me:

---------------------------------------------------------------------------------
STDMETHODIMP CAbxDTSCTString::Execute(
LPBYTE pvTransformServerData, // Transform server state data.
LPCDTSTransformColumnInfo pSrcColumnInfo, // Source columns and rowdata
LPDTSTransformColumnInfo pDestColumnInfo, // Dest columns and rowdata
IDTSDataConvert *pIDTSDataConvert, // Pointer to the data conversion
interface
LPDTSTransformStatus pTransformStatus // Result of transform
)
{

// Declarations
DTSColumnData* pDTSDestColumnData; // Destination column data pointer
const DBBINDING* pDBDestBinding; // Destination binding pointer
DTSColumnData* pDTSSourceColumnData; // Source column data pointer
const DBBINDING* pDBSourceBinding; // Source binding pointer
LPSTR pstrBuffer; // Buffer where the return data is being saved to
ULONG ulStatus; // Status of the source data (NULL, etc...)
ULONG ulSourceLength; // Length of the source data
ULONG ulDestLength; // Length of the destination data
ULONG* status; // Status of execution (success, error)
ULONG* ulLength; // Length of the returned data
LPSTR pSourceString; // Source data string
LPSTR pDestString; // Destination string
BOOL bDestWide; // Is destionation ASCII or UNICODE
(Wide)
BOOL bSourceWide; // Is source ASCII or UNICODE (Wide)


USES_CONVERSION;

for (UINT myCol = 0; myCol < pDestColumnInfo->cColumns; myCol++)
{

// Sets source column
pDTSSourceColumnData = &( pSrcColumnInfo->rgColumnData[myCol] );
pDBSourceBinding = pDTSSourceColumnData->pDBBinding;
bSourceWide = ( pDBSourceBinding->wType == DBTYPE_WSTR );
// Sets destination column
pDTSDestColumnData = &( pDestColumnInfo->rgColumnData[myCol] );
pDBDestBinding = pDTSDestColumnData->pDBBinding;
bDestWide = ( pDBDestBinding->wType == DBTYPE_WSTR );

// Get last name status, data length, data ptr.
ulStatus = *(ULONG *)( pDTSSourceColumnData->pvData +
pDBSourceBinding->obStatus );
ulSourceLength = *(ULONG *)( pDTSSourceColumnData->pvData +
pDBSourceBinding->obLength );
pSourceString = ( pDBSourceBinding->wType & DBTYPE_BYREF ?
*(LPSTR *)(pDTSSourceColumnData->pvData
+ pDBSourceBinding->obValue) :
(LPSTR)(pDTSSourceColumnData->pvData +
pDBSourceBinding->obValue) );

// Initializes pointer buffer
pstrBuffer = (LPSTR)new char[ ( (ULONG)m_Length1 + 1 ) *
( bDestWide ? 2 : 1 ) ];

// Sets status to Okay
status = (ULONG *)( pDTSDestColumnData->pvData + pDBDestBinding->obStatus );
*status = DBSTATUS_S_OK;

// Saves source string into the buffer
if ( ulStatus != DBSTATUS_S_ISNULL )
{
if ( bDestWide ) {
if ( bSourceWide )
wcscpy( (LPWSTR)pstrBuffer, (LPCWSTR)pSourceString );
else
wcscpy( (LPWSTR)pstrBuffer, (LPCWSTR)A2W( (LPCSTR)pSourceString) );
RemoveTrailingSpace( (LPWSTR)pstrBuffer, wcslen( (LPWSTR)pstrBuffer ) );
} else {
if ( bSourceWide )
strcpy( (LPSTR)pstrBuffer, (LPCSTR)W2A( (LPCWSTR)pSourceString) );
else
strcpy( (LPSTR)pstrBuffer, (LPCSTR)pSourceString );
RemoveTrailingSpace( (LPSTR)pstrBuffer, strlen( (LPSTR)pstrBuffer ) );
}
}


// Checks if source string is null, or equals "". In such case, it reads
// the default value, if there is one
if ( ulStatus == DBSTATUS_S_ISNULL || ulSourceLength == 0 || ( bDestWide ?
wcslen( (LPWSTR)pstrBuffer ) : strlen( (LPSTR)pstrBuffer ) == 0) )
{
// Saves default string to the buffer
if ( bDestWide )
wcscpy( (LPWSTR)pstrBuffer, m_DefaultValue.m_str );
else
strcpy( (LPSTR)pstrBuffer, W2A(m_DefaultValue.m_str) );
}

// Saves source data to destination column
ulLength = (ULONG *)( pDTSDestColumnData->pvData +
pDBDestBinding->obLength );
ulDestLength = pDBDestBinding->cbMaxLen;

if ( m_Length1 > 0 )
{
// Calc length of data (in bytes) to be moved
*ulLength = ( bDestWide ?
min( (ULONG)m_Length1 * 2, wcslen(
(LPCWSTR)pstrBuffer ) * 2 ) :
min( (ULONG)m_Length1, strlen(
(LPCSTR)pstrBuffer ) ) );
} else {
*ulLength = ( bDestWide ?
min( ulDestLength - 2, wcslen(
(LPCWSTR)pstrBuffer ) * 2 ) :
min( ulDestLength - 1, strlen(
(LPCSTR)pstrBuffer ) ) );
}
pDestString = (LPSTR)(pDTSDestColumnData->pvData + pDBDestBinding->obValue);
memcpy( pDestString, pstrBuffer, *ulLength );

// Terminates string
if( bDestWide )
*(LPWSTR)( pDestString + *ulLength ) = L'\0';
else
*(LPSTR)( pDestString + *ulLength ) = '\0';

}

if ( pstrBuffer )
delete( pstrBuffer );

return NOERROR;

}
---------------------------------------------------------------------------------

Regards,
Blaz


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.