Friday, March 30, 2012

ICommandText::Execute() causes mem leaks?

Howdy folks!

I'm trying the VS2005 addon Deleaker for the first time, and noticed I got about 40 "heap" memory leaks after the following m_pICmdText->Execute() call. Both m_pICmdText and m_pICmdPrepare are released before exiting the program. What else could cause these leaks? I've narrowed it down to only occuring if the execute statment is called. m_ulNumExecutions is 1 and a_pwszQuery is a CREATE TABLE statement:

// Set command sql query
hr = m_pICmdText->SetCommandText(DBGUID_SQL, a_pwszQuery);
CHKHR(hr, L"Failed to set command text\n", _ExitExeSql);

// Prepare command text for execution
hr = m_pICmdPrepare->Prepare(a_ulNumExecutions);
CHKHR(hr, L"Failed to prepare command text - Invalid Query\n", _ExitExeSql);

for(ULONG i=0;i<a_ulNumExecutions;i++)
{
//Execute query and place results in m_pIRowset
hr = m_pICmdText->Execute(NULL, IID_IRowset, NULL, NULL, (IUnknown **) &m_pIRowset);
CHKHR(hr, L"Failed to execute SQL\n", _ExitExeSql);
}

Thanks!
Jeff

Are you releasing the m_pIRowset variable?

|||Yes, but in this case it's not being used since it was a CREATE TABLE statement. My destructor is fairly thorough, but maybe I'm missing something:

Code Snippet

if(m_pIRowset!=NULL)

{
m_pIRowset->Release();
m_pIRowset = NULL;
}

if(m_pICmdPrepare != NULL)

{
m_pICmdPrepare->Release();
m_pICmdPrepare = NULL;
}

if(m_pICmdText != NULL)
{
m_pICmdText->Release();
m_pICmdText = NULL;
}

if(m_pIDBCrtCmd != NULL)
{
m_pIDBCrtCmd->Release();
m_pIDBCrtCmd = NULL;
}

if(m_pIDBCreateSession != NULL)
{
m_pIDBCreateSession->Release();
m_pIDBCreateSession = NULL;
}

if(m_pISequentialStream != NULL)
{
m_pISequentialStream->Release();
m_pISequentialStream = NULL;
}

if(m_pIUnknownSession != NULL)
{
m_pIUnknownSession->Release();
m_pIUnknownSession = NULL;
}

if(m_pIDBDataSourceAdmin != NULL)
{
m_pIDBDataSourceAdmin->Release();
m_pIDBDataSourceAdmin = NULL;
}

if(m_pIDBProperties != NULL)
{
m_pIDBProperties->Release();
m_pIDBProperties = NULL;
}

if(m_pIDBInitialize != NULL)
{
m_pIDBInitialize->Uninitialize();
m_pIDBInitialize->Release();
m_pIDBInitialize = NULL;
}


The "leak" that I get always has the following stack trace:
MSCVCR80.dll!_calloc_impl Line 94 (f:\sp\vctools\crt_bld\self_x86\crt\src\calloc.c)
MSCVCR80.dll!_calloc_crt Line 61 (f:\sp\vctools\crt_bld\self_x86\crt\src\crtheap.c)

I'm starting to wonder if it's just picking up the allocated space in the sql server engine transaction buffer. I noticed it doesn't give me leaks for SELECT statements.

sql

No comments:

Post a Comment