Reputation: 55
I have a code like-
void CSomeClass::Remove()
{
BSTR tempStr = NULL;
while(!m_list.IsEmpty()) //m_list is a CSomeClass member of type CList<BSTR, BSTR>
{
tempStr = m_list.RemoveHead(); //application crash here!!
if(NULL==tempStr)
continue;
}
SysFreeString(tempStr);
}
And I am not sure why the application got crash. Is it possible to initialize a BSTR to another BSTR using assignment operator? Can anyone help me in finding out why the application is crashing?
Upvotes: 0
Views: 328
Reputation: 1
Yes. BSTR can be assigned to another BSTR variable. BSTR is actually the starting address of the actual data.
The problem here is with the RemoveHead() function and not the assignment. Please see the complete stack trace or just attach a debugger to your program to debug the issue further.
Upvotes: 0
Reputation: 6050
Put the SysFreeString inside the loop
void CSomeClass::Remove()
{
BSTR tempStr = NULL;
while(!m_list.IsEmpty()) //m_list is a CSomeClass member of type CList<BSTR, BSTR>
{
tempStr = m_list.RemoveHead(); //application crash here!!
if(NULL==tempStr)
continue;
SysFreeString(tempStr);
}
}
Upvotes: -1