Re: Malloc/Free - freeing memory allocated by malloc
From: Richard Bos (rlb_at_hoekstra-uitgeverij.nl)
Date: 10/22/04
- Next message: Richard Bos: "Re: [OT] Undefined behavior?"
- Previous message: Richard Bos: "Re: Global Variables"
- In reply to: Richard Tobin: "Re: Malloc/Free - freeing memory allocated by malloc"
- Next in thread: Keith Thompson: "Re: Malloc/Free - freeing memory allocated by malloc"
- Reply: Keith Thompson: "Re: Malloc/Free - freeing memory allocated by malloc"
- Reply: Richard Tobin: "Re: Malloc/Free - freeing memory allocated by malloc"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 22 Oct 2004 07:45:14 GMT
richard@cogsci.ed.ac.uk (Richard Tobin) wrote:
> In article <41767a4c.179165393@news.individual.net>,
> Richard Bos <rlb@hoekstra-uitgeverij.nl> wrote:
>
> >> but dynamic alloc memory is not dealloc by OS at application teminated. why?
> >
> >Says who? On most OSes it is, and I'd call any modern OS on which it
> >isn't broken.
>
> A sensible, practical view.
>
> >and dereferencing a
> >null pointer causes just as undefined behaviour as dereferencing an
> >invalid pointer.
>
> A limited, theoretical view.
>
> A modern, general-purpose operating system that doesn't make
^^^^^^^^^^^^^^^
That is an extra requirement. Not everybody programs on Unix or MacOS.
> dereferencing a null pointer produce an immediate exception (at least
> by default) has a similar kind of "brokenness" to one which does not
> deallocate memory when a process terminates.
The real problem is not whether or not null pointer writes cause a
crash; the problem is that _relying_ on this behaviour, even on systems
where it does happen, is almost guaranteed to cause you to let down your
guard, and write through a copy of a free()d pointer which you forgot to
set to null when you free()d the original.
Richard
- Next message: Richard Bos: "Re: [OT] Undefined behavior?"
- Previous message: Richard Bos: "Re: Global Variables"
- In reply to: Richard Tobin: "Re: Malloc/Free - freeing memory allocated by malloc"
- Next in thread: Keith Thompson: "Re: Malloc/Free - freeing memory allocated by malloc"
- Reply: Keith Thompson: "Re: Malloc/Free - freeing memory allocated by malloc"
- Reply: Richard Tobin: "Re: Malloc/Free - freeing memory allocated by malloc"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|