S
Simon
Hi,
I have some old code that I am trying to use in my current project.
But my compiler is reporting a memory leak. (it does not tell me where the
leak comes from).
I have narrowed down the code as follow where the error could be.
// --
// in the header
std::string *m_pData;
//-------
// in the constructor
m_pData = new std::string[ someKnownSize + 1]
memset( m_pData, 0, (n+1)*sizeof(std::string) );
...
//-------
// The destructor
if( NULL != m_pData )
delete [] ( m_pData );
m_pData = NULL;
m_nSize = 0;
//-------
// in a function
void add( std::string &s, int len )
{
m_pData[m_nSize++] = std::string(s, len ) ;
}
//-------
if I remove the line "m_pData[m_nSize++] = std::string(s, len ) ;" then I
have no leak.
What could be the problem and how can I find the leak?
Many thanks
Simon
I have some old code that I am trying to use in my current project.
But my compiler is reporting a memory leak. (it does not tell me where the
leak comes from).
I have narrowed down the code as follow where the error could be.
// --
// in the header
std::string *m_pData;
//-------
// in the constructor
m_pData = new std::string[ someKnownSize + 1]
memset( m_pData, 0, (n+1)*sizeof(std::string) );
...
//-------
// The destructor
if( NULL != m_pData )
delete [] ( m_pData );
m_pData = NULL;
m_nSize = 0;
//-------
// in a function
void add( std::string &s, int len )
{
m_pData[m_nSize++] = std::string(s, len ) ;
}
//-------
if I remove the line "m_pData[m_nSize++] = std::string(s, len ) ;" then I
have no leak.
What could be the problem and how can I find the leak?
Many thanks
Simon