Home > Archive > MS SQLCE > July 2005 > Memory leak with IRowsetChange -> InsertRow









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Memory leak with IRowsetChange -> InsertRow
Sharon_a

2005-07-03, 3:23 am

Hello,
I'm using IRowsetChange->InsertRow and I found this function have memory
leak.
I get the NorthwindOleDb sample from the "Microsoft SQL Server CE 2.0"
installation folder.
I add loop on the row insertion at function : InsertEmployeeInfo

After this function the memory drop down until the application exists.

This is my new code part :
(I replaced this code in file "employees.cpp" at lines : 746 - 858


// Insert sample data
//
for (dwRow1 = 0; dwRow1 <
1000/ *sizeof(g_SampleEmpl
oyeeData)/ sizeof(g_SampleEmplo
yeeData[0])*/;
++dwRow1)
{
DWORD dwPhotoCol;
DWORD dwInfoSize;
LPWSTR lpwszInfo;

// Set data buffer to zero
//
memset(pData, 0, dwOffset);

for (dwCol = 0; dwCol < dwBindingSize; ++dwCol)
{
// Get column value in string
//
lpwszInfo = g_SampleEmployeeData
[0/*dwRow*/].wszEmployeeInfo[dwCol];

switch(prgBinding[dwCol].wType)
{
case DBTYPE_WSTR:
// Copy value to binding buffer, truncate the string if it is too long
//
dwInfoSize = prgBinding[dwCol].cbMaxLen/sizeof(WCHAR) - 1;
if (wcslen(lpwszInfo) >= dwInfoSize)
{
wcsncpy((WCHAR*)(pDa
ta+prgBinding[dwCol].obValue), lpwszInfo,
dwInfoSize);
*(WCHAR*)(pData+prgB
inding[dwCol]. obValue+dwInfoSize*s
izeof(WCHAR)) =
WCHAR('\0');
}
else
{
wcscpy((WCHAR*)(pDat
a+prgBinding[dwCol].obValue), lpwszInfo);
}

*(ULONG*)(pData+prgB
inding[dwCol].obLength) =
wcslen((WCHAR*)(pDat
a+prgBinding[dwCol]. obValue))*sizeof(WCH
AR);
*(DBSTATUS*)(pData+p
rgBinding[dwCol].obStatus) = DBSTATUS_S_OK;
break;

case DBTYPE_IUNKNOWN:
dwPhotoCol = dwCol;
break;

case DBTYPE_I4:
*(int*)(pData+prgBin
ding[dwCol].obValue) =
_wtoi(g_SampleEmploy
eeData[0/*dwRow*/].wszEmployeeInfo[dwCol]);
*(ULONG*)(pData+prgB
inding[dwCol].obLength) = 4;
*(DBSTATUS*)(pData+p
rgBinding[dwCol].obStatus) = DBSTATUS_S_OK;
break;

default:
break;
}
}

// Insert data to database
//
hr = pIRowsetChange-> InsertRow(DB_NULL_HC
HAPTER, hAccessor, pData,
prghRows);
if (FAILED(hr))
{
goto Abort;
}

// Get the row data
//
hr = pIRowset->GetData(rghRows[0], hAccessor, pData);
if(FAILED(hr))
{
goto Abort;
}

// Check the status
//
if (DBSTATUS_S_OK !=
*(DBSTATUS*)(pData+p
rgBinding[dwPhotoCol].obStatus))
{
hr = E_FAIL;
goto Abort;
}

// Insert photo into database through ISequentialStream
//
pISequentialStream = (*(ISequentialStream
**) (pData +
prgBinding[dwPhotoCol].obValue));
if (pISequentialStream)

{
// Insert photo
//
hr = SaveEmployeePhoto(pI
SequentialStream,
g_SampleEmployeeData
[0/*dwRow*/].dwEmployeePhoto);
if(FAILED(hr))
{
goto Abort;
}

// Release ISequentialStream interface
//
hr = pISequentialStream->Release();
if(FAILED(hr))
{
pISequentialStream = NULL;
goto Abort;
}

pISequentialStream = NULL;
}

// Release the rowset
//
hr = pIRowset->ReleaseRows(1, prghRows, NULL, NULL, NULL);
if(FAILED(hr))
{
goto Abort;
}

prghRows[0] = DB_NULL_HROW;
}



Thanks,
Sharon


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com