🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pilot.programmer.codewarrior
Article #24

Re: char* memory leak with emulator 3.5

#24
From: David Ladanyi
Date: Tue, 08 Oct 2002 17:05
68 lines
3556 bytes
When I put in a "delete psaStr" line it produced a memory error
because the pointer was being used by the field. I managed to fix the
problem by declaring "char psaStr[6];" instead of "char* psaStr = new
char[6];"


"Baxter" <baxter.spamblock@baxcode.com> wrote in message news:<uq35nhqhshk23@corp.supernews.com>...
> Somewhere in your code, you need a:
> 
> delete psaStr;
> 
> --
> -------------------------------------------------------------------------
> Free software  - Baxter Codeworks  www.baxcode.com
> -------------------------------------------------------------------------
> 
> 
> "David Ladanyi" <david_ladanyi@yahoo.com> wrote in message
> news:30890494.0210062256.7a8a8fa@posting.google.com...
> > Hi
> >
> > I have a program that seems to run fine in the emulator except that
> > whenever I try to close the program I'm told that I have a memory
> > leak. I've figured out what statement is causing the leak but I can't
> > figure out how to fix it. This code is called when a certain form is
> > being initialized:
> >
> > double psaVal = pronData->pretx_psa;
> > char* psaStr = new char[6];
> >
> > if(psaVal != NO_VALUE) {
> > doubleToStr(psaStr, psaVal, 1);
> > }
> > else
> > psaStr = "";
> >
> > SetFieldHandle(GetObjectPtr<FieldType>( PreTxPSAField), psaStr);
> >
> > This code simply creates a string from a double and sets a field to
> > that string. The memory leak was caused by the "new char[6]" line so I
> > put in a deallocation function that would be called when the form
> > receives a frmCloseEvent (I made sure to set handled=false):
> >
> > void PreTxCleanUp() {
> >
> >         FormType* frmP = FrmGetActiveForm();
> > FieldType* field = (FieldType*)
> > FrmGetObjectPtr(frmP,FrmGetObjectIndex (frmP, PreTxPSAField));
> >
> > MemHandle refs = FldGetTextHandle(field);
> >
> > if(refs != NULL) {//  && MemHandleUnlock(refs) != memErrInvalidParam)
> > {
> > FldSetTextHandle (field, NULL);
> > MemHandleFree(refs);
> > }
>  
> > }
> >
> > This function doesnt give any errors buy it also doesn't fix the
> > problem. Every time I open and close the form in question it creates a
> > leaked memory chunk. Am I not de-allocating the memory properly or is
> > there a problem with the emulator? Also, if the memory leak is caused
> > by a variable local to a certain form why isn't the emulator telling
> > me about the leak as soon as I close the form as opposed to waiting
> > until I close the whole program? Thanks in advance for any advice.
> >
> > Dave
Technical Details
Message-ID: <30890494.0210080905.64899638@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
References: <30890494.0210062256.7a8a8fa@posting.google.com> <uq35nhqhshk23@corp.supernews.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109d41,fc0bc5958a8d445f
X-Google-Attributes: gid109d41,public
X-Google-Thread: 10baa0,fc0bc5958a8d445f
X-Google-Attributes: gid10baa0,public
X-Google-ArrivalTime: 2002-10-08 10:05:25 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
From: david_ladanyi@yahoo.com (David Ladanyi)
Newsgroups: pilot.programmer.codewarrior,codewarrior.palm
Subject: Re: char* memory leak with emulator 3.5
Date: 8 Oct 2002 10:05:25 -0700
Organization: http://groups.google.com/
Lines: 68
Message-ID: <30890494.0210080905.64899638@posting.google.com>
References: <30890494.0210062256.7a8a8fa@posting.google.com> <uq35nhqhshk23@corp.supernews.com>
NNTP-Posting-Host: 140.163.94.51
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1034096725 16091 127.0.0.1 (8 Oct 2002 17:05:25 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 8 Oct 2002 17:05:25 GMT