Re: new char

From: Rolf Magnus (ramagnus_at_t-online.de)
Date: 10/19/04


Date: Tue, 19 Oct 2004 18:55:11 +0200

SJ wrote:

> Hi:
>
> I am reviewing some bad code. Help me on this! The following is a
> modified version of the code.
>
> whie(some condition)
> {
> char *x;
> x = new char(' ');
> foo(x);
> }
> The variable x is not deleted. So, there is a memory leak?

If it's not deleted, yes. But are you sure that foo() doesn't delete it?

> This code sometimes crashes with a "memory could not be read" problem.

A memory leak means that you just waste memory by not freeing it after you
need it. But such a crash usually has another reason.

> Can anyone explain me the internals of how memory is handled and what
> causes the problem?

That's dependant on the platform and on the code. You might see such errors
e.g. when attempting to delete memory twice or when trying to access memory
that you didn't allocate before or that you already deallocated.



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)