Article View: comp.sys.mac.programmer.codewarrior
Article #1414Re: [help] Why does this leak?
From: Howard Hinnant
Date: Mon, 02 Oct 2000 00:00
Date: Mon, 02 Oct 2000 00:00
66 lines
3214 bytes
3214 bytes
In article <8rao64$4u3$1@nnrp1.deja.com>, petrock <petrock00@my-deja.com> wrote:
| Hello,
| I am using Codewarrior Pro 5.3, with a newly installed Univ
| Interface 3.3.2. Here is the problem. I ran a program that I wrote
| through Spotlight. Spotlight said I was leaking. i looked and I'm not.
| So I created a test project (C++ console app) to see if it was me or
| Spotlight... here is the code
|
| #include <stdio.h>
| #include <stdlib.h>
| #include "SpotlightAPI.h"
|
| using namespace std; //introduces namespace std
|
| int main()
| {
| printf("about to allocate memory\n") ;
| char * tmp = (char*) malloc(100); // this leaks
|
| free(tmp);
| printf("free'd memory\n") ;
| return(0) ;
| }
|
| Spotlight says that this is leaking. This is the exact code I have in
| the test source file. Didn't change a thing... I thought that it might
| be that my univ interfaces got screwed up, so I installed a fresh copy,
| re-compiled all the headers etc... same problem. If I use "new" instead
| of malloc or even calloc, I get the same problem. but if I use NewPtr
| the problem goes away... I don't understand this. Does anyone have an
| idea? Thanks...
|
| here is the output from Spotlight
| Spotlight (1.0) log for: Test.out.xSYM
|
| Mon, Oct 2, 2000 3:17 PM
|
| ** Leaked Ptr blocks:
|
| Size: 65536 bytes
| Stack trace:
| __sys_alloc
| link_new_block
| allocate_from_var_pools
| malloc
| main (HelloWorld.cp 20)
I took your sample, removed the Spotlight include (I don't have
Spotlight), turned on symbolics in the C lib and put a break point in
__sys_alloc and __sys_free in pool_alloc.mac.c, and ran the code in the
debugger.
Under main/malloc/.../__sys_alloc a call to NewPtr returned with the value
0x03040C80. Then under main/free/.../__sys_free a call to DisposePtr was
made with the argument 0x03040C80. No other calls to __sys_alloc or
__sys_free were made. <shrug> I don't see any leaks.
FWIW, Pro 6 has a C lib flag: _MSL_OS_DIRECT_MALLOC which turns off the
pooling that malloc/free does. Every call will go straight to
NewPtr/DisposePtr. This may keep Spotlight from reporting false
positives, but that's only a guess. I would not have expected Spotlight
to flag this one as the pool is dumped under the free in this example
(unless the Spotlight include is causing a memory allocation).
-Howard
Technical Details
Message-ID:
<hinnant-0210001614570001@ith3-3d8.twcny.rr.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<8rao64$4u3$1@nnrp1.deja.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10bcce,f4b1d593e54aa750 X-Google-Attributes: gid10bcce,public X-Google-Thread: f635e,f4b1d593e54aa750 X-Google-Attributes: gidf635e,public From: hinnant@anti-spam_metrowerks.com (Howard Hinnant) Subject: Re: [help] Why does this leak? Date: 2000/10/02 Message-ID: <hinnant-0210001614570001@ith3-3d8.twcny.rr.com> X-Deja-AN: 676763051 References: <8rao64$4u3$1@nnrp1.deja.com> X-Complaints-To: abuse@twcny.rr.com X-Trace: typhoon.nyroc.rr.com 970517472 24.24.13.216 (Mon, 02 Oct 2000 16:11:12 EDT) Organization: Metrowerks NNTP-Posting-Date: Mon, 02 Oct 2000 16:11:12 EDT Newsgroups: comp.sys.mac.programmer.codewarrior,comp.sys.mac.programmer.codewarrior,codewarrior.mac