Wouldn't this be safe (for malloc)??
CString str;
char *tmp = NULL;
try
{
str = "Hello";
tmp = (char *)malloc(str.GetLength() + 1);
if (tmp)
{
wcstombs(tmp, str, str.GetLength());
LibraryFuncCall(tmp);
free(tmp);
tmp = NULL;
}
}
catch(...)
{
if (tmp)
free(tmp);
}
----- Original Message -----
From: "Paul Grenyer" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, April 02, 2004 2:41 AM
Subject: Re: [msvc] CString and unicode
> Hi
>
> Just some observations:
>
> > CString str("hello");
> > char* tmp = (char*)malloc(str.GetLength() + 1);
> > wcstombs(tmp, str, str.GetLength());
> > LibraryFuncCall(tmp);
> > free(tmp);
>
> malloc? free? This is C++ isn't it? Shouldn't you be suing new and
> delete? What if wcstombs or LibraryFuncCall trhow an exception? You'd
> get a memory leak! Try using boost's (www.boost.org) array pointer and
> new and delete instead.
>
> Regards
> Paul
>
> Paul Grenyer
> Email: [EMAIL PROTECTED]
> Web: http://www.paulgrenyer.co.uk
>
> Have you met Aeryn: http://www.paulgrenyer.co.uk/aeryn/?
> Version 0.3.0 beta now available for download.
>
>
>
> _______________________________________________
> msvc mailing list
> [EMAIL PROTECTED]
> See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for
subscription changes, and list archive.
>