-
May 11th, 2010, 11:20 PM
#1
Cleaning up strings
Hi all,
Given this code, I want to make sure that there are no leaks from the strings that I have used:
#include <atlstr.h>
...
string varVarName = GetAttribute("VarIn", pNodeMap);
string stringIn = getDictionary(varVarName);
CString cstrIn = CString(stringIn.c_str());
cstrIn.Trim();
CT2CA pszConvertedAnsiString(cstrIn);
std::string strOut(pszConvertedAnsiString);
From what I understand, I think that I do not need to free std::strings as the program automatically frees those. I am not sure regarding CStrings, although I also believe that the program handles those.
What I know is that from the many string types in C++, only BSTR require freeing if you have called AllocSysString on it or equate it to NULL.
Can you help me understand why you need to free BSTR and not std::string, CString, etc.?
Thank you!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|