Memory leak in ev.c

Marc Lehmann schmorp at
Wed Feb 20 18:35:49 CET 2013

On Wed, Feb 20, 2013 at 12:24:35PM -0500, Kevyn-Alexandre Paré <kapare at> wrote:
> My only concern about this way of freeing is about that post:

I am not a friend of the secure coding standards, and this is a good
example why:

Basically it says that when you allocate n bytes, you shouldn't access
anything beyond those n bytes.

Except it only talks about the very special and unimportant case n == 0,
while the cases where n > 0 are much more common in practise. But overall,
it's trivial.

The explanation of why you shouldn't has nothing to do with the special
semantics of realloc etc., or with the size being 0.

It does get some points for talking about the problem of realloc failing,
but a thorough discussion about this problem would have been much better
and more useful than saying that accessing memory behind a pointer to a
zero-sized memory area is invalid because it is beyond the allocated area,
and therefore implying that this might not be so if the size is not zero.

That strongly reminds me of the prof. at the university who once told his
students that in a U-pipe, IF the two pipes have the same diameter, THEN
the liquid level is the same in both pipes, causing one of his doctorands
to exclaim later:

"wow, this is great, you go to the beach, make a small hole and the water
will just GUSH OUT in a big fountain!"

No, really, the secure coding standards are an unholy mix of very
dangerous ideas and very important issues, and are not very useful unless
you already know most of these issues.

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_    
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list