Article View: borland.public.cppbuilder.nativeapi
Article #11821Re: std::string to BSTR conversion function leaks memory... (Urgent please)
From: Ed Mulroy [TeamB]
Date: Fri, 16 Jan 2004 15:30
Date: Fri, 16 Jan 2004 15:30
37 lines
1936 bytes
1936 bytes
I can't see anything that leaks in that code. Could it be that the program
which uses the function does not free the returned string with
SysFreeString?
. Ed
> Fernando wrote in message
> news:bjlf005pg85nvabmpc7ksd5ugs624tua53@4ax.com...
>
> 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:-)
Technical Details
Message-ID:
<4008039f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<bjlf005pg85nvabmpc7ksd5ugs624tua53@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,61db49fd5c05f5b0 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-01-16 07:40:38 PST From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> Newsgroups: borland.public.cppbuilder.nativeapi References: <bjlf005pg85nvabmpc7ksd5ugs624tua53@4ax.com> Subject: Re: std::string to BSTR conversion function leaks memory... (Urgent please) Date: Fri, 16 Jan 2004 10:30:38 -0500 Lines: 39 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 24.74.175.102 Message-ID: <4008039f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1074267039 24.74.175.102 (16 Jan 2004 07:30:39 -0700) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail