Article View: borland.public.cppbuilder.nativeapi
Article #11817std::string to BSTR conversion function leaks memory... (Urgent please)
From: Fernando
Date: Fri, 16 Jan 2004 15:01
Date: Fri, 16 Jan 2004 15:01
31 lines
1471 bytes
1471 bytes
Hi,
Allthough CodeGuard doesn't report it, this function leaks memory:
BSTR string2BSTR( const string & input )
{
int destSize = input.size() + 1;
wchar_t * rc;
wchar_t * wc = new wchar_t[destSize];
BSTR res;
rc = ::StringToWideChar(input.c_str(), wc, destSize);
if( rc == wc )
{
// it worked
res = ::SysAllocString(wc);
}
else
{
// it didn't
res = ::SysAllocString(L"");
}
delete[] wc;
return res;
}
I can't find the error... What am I doing wrong? O:-)
Thanks
Technical Details
Message-ID:
<bjlf005pg85nvabmpc7ksd5ugs624tua53@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,61db49fd5c05f5b0,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-01-16 07:10:24 PST From: Fernando <frr@easyjob.net> Newsgroups: borland.public.cppbuilder.nativeapi Subject: std::string to BSTR conversion function leaks memory... (Urgent please) Date: Fri, 16 Jan 2004 16:01:03 +0100 Message-ID: <bjlf005pg85nvabmpc7ksd5ugs624tua53@4ax.com> X-Newsreader: Forte Agent 1.9/32.560 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 217.127.66.80 X-Trace: newsgroups.borland.com 1074265264 217.127.66.80 (16 Jan 2004 07:01:04 -0700) Lines: 31 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail