Re: Memory leak when internal pointer passed out as parameter
- From: Daniel Rudy <spamthis@xxxxxxxxxxxx>
- Date: Wed, 04 Apr 2007 10:01:26 GMT
At about the time of 4/3/2007 11:52 AM, Mike stated the following:
On Apr 3, 2:29 pm, rober...@xxxxxxxxxxxxxxxxxx (Walter Roberson)
wrote:
In article <1175623345.081280.166...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Mike <mail...@xxxxxxxxx> wrote:
I have following existing code. And there is memory leak. Anyone knowAre you certain that it is a memory leak, and not a memory
how to get ride of it?
fragmentation problem?
--
All is vanity. -- Ecclesiastes
Rational Purify checked the code, and reported memory leak on foo1
when we allocate memory. I assum e that the compiler will allocate a
new block of memory when foo1 returns. Then the memory allocated
within foo1 will remain in the system heap forever. However I have no
way to verify it.
The allocated memory will be returned to the system heap when the
program exits, if there is a memory leak. I don't see a memory leak
either. The function foo1 calls calloc and returns the resulting
pointer, then the pointer is freed in you code.
A couple of points to make though:
1. Main is not declared correctly. It should be one of the two
following examples:
int main(void)
---or---
int main(int argc, char **argv)
In either case, you need to have a return at the end of your main function.
2. Your cast in calloc is not necessary...unless you are using C++, but
then you would need to head on over to c.l.c++ to ask your question.
--
Daniel Rudy
Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m
Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
.
- Follow-Ups:
- References:
- Memory leak when internal pointer passed out as parameter
- From: Mike
- Re: Memory leak when internal pointer passed out as parameter
- From: Walter Roberson
- Re: Memory leak when internal pointer passed out as parameter
- From: Mike
- Memory leak when internal pointer passed out as parameter
- Prev by Date: Re: K&R2, 1.5.1 example
- Next by Date: Re: What's going on with C Compilers and C99??
- Previous by thread: Re: Memory leak when internal pointer passed out as parameter
- Next by thread: Re: Memory leak when internal pointer passed out as parameter
- Index(es):
Relevant Pages
|