🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.mac.programmer.codewarrior
2 messages
2 total messages Started by petrock Mon, 02 Oct 2000 00:00
[help] Why does this leak?
#1413
Author: petrock
Date: Mon, 02 Oct 2000 00:00
53 lines
2150 bytes
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)

--Rob




Sent via Deja.com http://www.deja.com/
Before you buy.
Re: [help] Why does this leak?
#1414
Author: Howard Hinnant
Date: Mon, 02 Oct 2000 00:00
66 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads