This is the mail archive of the
mailing list for the glibc project.
Re: malloc problem/question in 2.1.3
- To: glibc-linux at ricardo dot ecn dot wfu dot edu
- Subject: Re: malloc problem/question in 2.1.3
- From: Mike Corbeil <mcorbeil at netrevolution dot com>
- Date: Thu, 01 Jun 2000 15:06:14 -0400
- References: <200005312024.QAA05054@onsager.chem.mcgill.ca>
- Reply-To: glibc-linux at ricardo dot ecn dot wfu dot edu
David Ronis wrote:
> Please ignore my previous post, I'd been free'ing an unrelated (and unused)
> block of memory when I shouldn't have been. I don't understand exactly
> why this should give a SIGSEGV, but it's fixed.
As you probably guessed, this is because free doesn't (at least didn't in this
case) check if the argument is valid or not, that is, if there's actually any
memory attached to the pointer passed as an argument. However, why free
wouldn't check for something like this leaves guess work.
If I'm not mistaken, then I vaguely recall someone saying, numerous years ago,
that free couldn't check this and that this is why free isn't as reliable or
friendly as some or many would like.
As a short aside, I think that this could be checked for in Perl using
"defined" (e.g., if defined $var ...), however C is a compiled language and I
don't think there's any such functionality, not afaik anyway.
I think that you're correct to be surprised that free didn't catch this and
this then caused a sigsegv, but I believe that there's a technical reason why
this condition isn't checked for and handled by free.
Although, this might be a little off topic for this mailing list, perhaps this
will help to generate some education, for some readers anyway, like myself.
Or, it'll just be a refresher.