V
Vivienne
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 SStringToBstring(System::String ^ s, std::string& os ){
using namespace Runtime::InteropServices;
pin_ptr<const wchar_t> wch = PtrToStringChars(s);
size_t convertedChars = 0;
size_t sizeInBytes = ((s->Length + 1) * 2);
errno_t err = 0;
char *ch = (char *)malloc(sizeInBytes);
err = wcstombs_s(&convertedChars, 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
+
+ reports memory leaking in this function. But I don't know why?
void SStringToBstring(System::String ^ s, std::string& os ){
using namespace Runtime::InteropServices;
pin_ptr<const wchar_t> wch = PtrToStringChars(s);
size_t convertedChars = 0;
size_t sizeInBytes = ((s->Length + 1) * 2);
errno_t err = 0;
char *ch = (char *)malloc(sizeInBytes);
err = wcstombs_s(&convertedChars, 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