This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

Memory leak in cpplex.c


Clearly not many people bootstrap the compiler on machines with only 32Mbytes of memory
these days, or they would have noticed a rather dramatic increase in
compilation times.

It turns out that if _cpp_get_buff is asked for a buffer of size zero, it
will reject every free buffer, even if it is the minimum size.  Finally it
will then allocate a new minimum size buffer to fulfil the request.

Fix is quite obvious: allow a request for zero bytes to be satisfied by a
minimum-size buffer.

Bootstrapped on arm-netbsd, where this fix reduced heap usage when
compiling f/intrin.c by >90% and compile time from >12 Hours to 30 seconds.

R.

2001-10-17  Richard Earnshaw <rearnsha@arm.com>

        * cpplex.c (_cpp_get_buff): Fix off-by-one error that caused memory
        leak.


Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v
retrieving revision 1.175
diff -p -r1.175 cpplex.c
*** cpplex.c	2001/10/11 21:21:57	1.175
--- cpplex.c	2001/10/17 16:16:32
*************** _cpp_get_buff (pfile, min_size)
*** 2116,2122 ****
        size = result->limit - result->base;
        /* Return a buffer that's big enough, but don't waste one that's
           way too big.  */
!       if (size >= min_size && size < BUFF_SIZE_UPPER_BOUND (min_size))
  	break;
      }
  
--- 2116,2122 ----
        size = result->limit - result->base;
        /* Return a buffer that's big enough, but don't waste one that's
           way too big.  */
!       if (size >= min_size && size <= BUFF_SIZE_UPPER_BOUND (min_size))
  	break;
      }
  

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