[PATCH 3/5] Move the memory allocation of entry buffers to a separate function

Linus Torvalds torvalds at linux-foundation.org
Thu Dec 27 10:39:48 PST 2012


On Thu, Dec 27, 2012 at 8:14 AM, Dirk Hohndel <dirk at hohndel.org> wrote:
>
> I'm not sure I like this change. It seems to make the code more
> complicated in order to improve memleak debugging. I am a little less
> worried about memleaks in the parser and more concerned about
> readability and debuggability of the code. But could be convinced
> otherwise.
>
> Linus, what do you think?

I agree.

If we start doing things like this, I'd rather go *much* further, and
remove the allocation entirely, and create a new

   struct xmlcontent {
      int size;
      const char *buf;
   };

thing, and pass a pointer to that in to all the parsing functions (and
all the way up into visit_one_node() which is where the buffer gets
created). The parsing functions generally don't need the allocation
anyway, and will only do a "free()" on it immediately after parsing
it.

We know the buffer is NUL-terminated anyway, although there may be
extra whitespace after 'size'. So 99% of all the parsing functions
don't really need to re-allocate the buffer. The ones that do are
string things, and doing a malloc there, rather than earlier, should
be simple.

                 Linus


More information about the subsurface mailing list