This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Memory leak in cpplex.c
- To: gcc-patches at gcc dot gnu dot org, neil at daikokuya dot demon dot co dot uk
- Subject: Memory leak in cpplex.c
- From: Richard Earnshaw <rearnsha at arm dot com>
- Date: Wed, 17 Oct 2001 17:25:38 +0100
- cc: Richard dot Earnshaw at arm dot com
- Organization: ARM Ltd.
- Reply-To: Richard dot Earnshaw at arm dot com
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;
}