This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] alloca is dangerous to users health
- To: egcs-bugs at egcs dot cygnus dot com, egcs-patches at egcs dot cygnus dot com, egcs at egcs dot cygnus dot com, robertl at sco dot com
- Subject: [patch] alloca is dangerous to users health
- From: korbb at egcs dot cygnus dot com
- Date: 29 Apr 1999 05:21:14 -0000
- Cc: ddsinc09 at ix dot netcom dot com
Reply-To: ddsinc09@ix.netcom.com
After spending more time than I want to admit pouring
over my fixincl code and finding no trouble on my GCC/EGCS
compiled systems, I have now found a memory leak for most
other systems. This program calls regexec tens or hundreds
of thousands of times. Every time from the same place in
the stack. regexec will, on some systems, call malloc.
However, it will only free that memory if the alloca
emulation routine is called from a spot further down in
the stack. That never happens. Oops.
Suggested rule: Never use alloca. It is not efficient
enough to be worth it. Never ever. Don't.
So, is this patch putrid enough to ship?
Index: fixincl.c
===================================================================
RCS file: /cvs/egcs/egcs/gcc/fixinc/fixincl.c,v
retrieving revision 1.6
diff -C5 -r1.6 fixincl.c
*** fixincl.c 1999/04/26 10:38:38 1.6
--- fixincl.c 1999/04/29 05:08:31
***************
*** 302,311 ****
--- 302,314 ----
else if (pz_data = load_file (pz_file_name),
(pz_data != (char *) NULL))
{
if (strstr (pz_data, gnu_lib_mark) == (char *) NULL)
process (pz_data, pz_file_name);
free ((void *) pz_data);
+ # ifdef C_ALLOCA
+ alloca (0);
+ # endif
}
}
return EXIT_SUCCESS;
}