RE: Bug/Memory Leak in sm_Attr.cpp
"Colestock, Robert" <[email protected]> Tue, 18 Sep 2001 12:35:33 -0400
| Newsgroups | gmane.ietf.sfl |
|---|---|
| Message-ID | <[email protected]> |
William: You are correct. I have been finding such discrepencies in the SFL and cleaning them up. Thank you for pointing this out. It will be fixed in the next release. In the mean-time, there is an "=" operator overload that works correctly, you can use the default constructor and simply assign the result. Bob Colestock VDA. -----Original Message----- From: William Adams [mailto:[email protected]] Sent: Tuesday, September 18, 2001 11:02 AM To: SFL List (E-mail) Subject: Bug/Memory Leak in sm_Attr.cpp 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