Below is a function that convert a System::String to basic string. VC
+
+ reports memory leaking in this function. But I don't know why?
void SStringToBstrin g(System::Strin g ^ s, std::string& os ){
using namespace Runtime::Intero pServices;
pin_ptr<const wchar_twch = PtrToStringChar s(s);
size_t convertedChars = 0;
size_t sizeInBytes = ((s->Length + 1) * 2);
errno_t err = 0;
char *ch = (char *)malloc(sizeIn Bytes);
err = wcstombs_s(&con vertedChars, ch, sizeInBytes, wch,
sizeInBytes);
os = native_os; //here is the position where memory leaks!
free(ch);
}
can someone tell me why? and how to edit it?
Vivienne