Article View: borland.public.cppbuilder.nativeapi
Article #17061Re: Fixing a memory leak
From: Remy Lebeau (TeamB)
Date: Fri, 11 Apr 2003 19:35
Date: Fri, 11 Apr 2003 19:35
26 lines
1525 bytes
1525 bytes
"JD" <nospam@nospam.com> wrote in message
news:3e970049$1@newsgroups.borland.com...
> Try this:
<snip>
That is not valid. The memory was allocated as a char[] but then you're
freeing it as a People* instead. They must match. So the memory has to be
freed as a char* using delete[] instead:
char *pBuf = ReadFileToBuffer("Database.dat", &FileSize);
if( pBuf )
{
PeopleType *People = (PeopleType*)pBuf;
// use People as needed
delete[] pBuf;
}
> BTW: It is permissable to delete a NULL pointer in C++
Yes.
Gambit
Technical Details
Message-ID:
<3e971900$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3e96fe40$1@newsgroups.borland.com> <3e970049$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,23a77f481a630239 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-04-11 12:44:05 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3e96fe40$1@newsgroups.borland.com> <3e970049$1@newsgroups.borland.com> Subject: Re: Fixing a memory leak Date: Fri, 11 Apr 2003 12:35:54 -0700 Lines: 28 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3e971900$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1050089728 207.175.226.26 (11 Apr 2003 12:35:28 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail