Bug/Memory Leak in sm_Attr.cpp
William Adams <[email protected]> Tue, 18 Sep 2001 17:02:25 +0100
| Newsgroups | gmane.ietf.sfl |
|---|---|
| Message-ID | <000201c1405b$4f762930$8b353fc1@dell32022k> |
I think I have found a problem with the CSM_ContentHints *CSM_MsgAttributes::GetContentHints() function in sm_Attr.cpp line 2603. I was using this function assuming that I was returned a copy of the m_pContentHints member of the class. Therefore once I had finished with my copy I deleted it. However this would cause the program to crash since the memory was being deleted twice. A closer inspection of the code reveals that the copy is made using a default copy constuctor pContentHints = new CSM_ContentHints(*tmpAttrib->m_pContentHints); Since m_pContentHints is a CSM_Buffer* then the copy constructor just copies the pointer instead of what it points to meaning that the m_pContentHints in both the original and the copy point to the same area of memory. Thus if you delete the copy when you are finished with it then the CSM_Buffer ends up being deleted twice. However if you do not delete the copy then you will have a memory leak since the rest of the memory allocated for the copy is not cleaned up. Am I correct about this? -Will