Re: Malloc code

Tech-Archive recommends: Fix windows errors by optimizing your registry



However, it is considered a good programming habit by some to set pointers
to null when the associated memory is released. That's to protect you from
yourself. If you accidently try to dereference the pointer after it has
been set to null, this will cause your program to crash. Imagine if you
didn't reset the pointer to 0. Then you would be using deallocated memory,
which usually leads to

Probably not. On embedded systems with no mmu, address zero is valid.

memory corruption. The problem is that your program is likely to trundle
along for quite some time before dying mysteriously and ignominously.
These kind of bugs are notoriously difficult to debug.

Scope control is really the only thing that helps when running without an
mmu.


.



Relevant Pages

  • Re: Pointer and Its memory
    ... I dereference the pointer A using free. ... That is deallocating the memory it points at. ... Note that heap memory is an implementation detail, and not all systems even have a heap. ...
    (comp.lang.c)
  • Re: Confused about "void **"
    ... You cannot dereference a `void*' because ... memory of unknown size and significance. ... And what kind of a pointer points to a `void*'? ... of data object, ...
    (comp.lang.c)
  • Re: Validate a pointer
    ... >> damage has been done. ... > the pointer - the memory you trash will be the memory of the child ... My point was that by the time you decide to dereference your possibly ... invalid pointer, lots of data might have be trampled on. ...
    (comp.unix.programmer)
  • Re: end of array
    ... You can make a pointer point to anything. ... I will probably get a segmentation fault or a memory fault. ... You don't have to attempt to dereference the pointer to invoke undefined behaviour. ... Merely calculating a pointer before or more than 1 past the end of an object invokes undefined behaviour even if you do nothing with it. ...
    (comp.lang.c)
  • Re: Is this math test too easy?
    ... > communications glitch; one of the more laughable cartoons ... it was loaded into physical memory and, ... > Or one can interpret the character string as one of the values ... A pointer to an integer? ...
    (sci.math)