Re: Memory leak when internal pointer passed out as parameter



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 know
how to get ride of it?
Are you certain that it is a memory leak, and not a memory
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
.



Relevant Pages

  • [NT] Services for UNIX 2.0 Suffer from a Remotely Triggered Memory Leak
    ... Services for UNIX 2.0 Suffer from a Remotely Triggered Memory Leak ... 2000 are not affected by the vulnerability. ... * A vulnerability that could enable an attacker to cause the NFS service ...
    (Securiteam)
  • RE: Memory increasing even when in debug-break
    ... there are 2 types of memory leak in .Net: ... More interesting is the debugger breaks while memory still increasing ... Microsoft Online Community Support ...
    (microsoft.public.vsnet.debugging)
  • Re: Memory leak in the Driver
    ... will it also work for device driver ??? ... if the following application is used then, there is no memory leak. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Memory Leak
    ... Regarding .Net memory leak issue, an important step is determing if it is ... should not use the "Mem Usage" column in task manager which is misleading. ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Memory Leak
    ... managed leak or unmanaged memory leak. ... should not use the "Mem Usage" column in task manager which is misleading. ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.csharp)