Fix obscure obstack bug

Ulrich Drepper drepper@redhat.com
Fri Dec 14 16:31:00 GMT 2001


I finally looked at this and don't see anthing wrong with the current
code.  Instead, your test program is faulty:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void *
my_alloc (size_t size)
{
  /* Grow the chunks up to a point.  */
#if SHOW_BUG
  if (obstack_chunk_size (&ob) < 100 * 1024)
    obstack_chunk_size (&ob) += 4 * 1024;
#endif
  return malloc (size);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You increase the chunk size but don't allocate enough memory.  You
want to compensate for this by changing the obstack code to not look
at the current chunk size and instead use what was previously
computed.  That's wrong and can break existing code.

If you want to fuzz around with the chunk size change the last line of
your function to

  return malloc (obstack_chunk_size (&ob));

This way you can control the chunk size and the changes are
automatically picked up in the obstack functions.  With your patch
applied this wouldn't be the case.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------



More information about the Libc-alpha mailing list