This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: malloc problem/question in 2.1.3


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.

mike



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]