From 64b09cd68e003f3f1c1b71284aceb90b9c236f05 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 21 Jan 2010 07:04:40 -0800 Subject: Fix for unbounded memory growth problem reproduced with GCC 4.4.1 on 32 bit x86 Fedora. This happens because the lazy list variable ``data'' in the match_files function is optimized to a register, but a stale value of that variable persists in the backing storage. --- ChangeLog | 14 ++++++++++++++ gc.c | 17 +++++++++++++++++ gc.h | 2 ++ match.c | 2 ++ 4 files changed, 35 insertions(+) diff --git a/ChangeLog b/ChangeLog index 96c99930..9871e1a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2010-01-21 Kaz Kylheku + + Fix for unbounded memory growth problem reproduced with GCC 4.4.1 + on 32 bit x86 Fedora. This happens because the lazy list variable + ``data'' in the match_files function is optimized to a register, + but a stale value of that variable persists in the backing storage. + + * gc.h (gc_hint): New macro. + (gc_hint_func): Declared. + + * gc.c (gc_hint_func): New function. + + * match.c (match_files): Use gc_hint on the data lazy list. + 2010-01-21 Kaz Kylheku * match.c (match_files): Reduce scope, and bogus use of, dataline diff --git a/gc.c b/gc.c index 2a659e2b..284ca711 100644 --- a/gc.c +++ b/gc.c @@ -486,3 +486,20 @@ void unmark(void) } } } + +/* + * This function does nothing. + * gc_hint(x) just takes the address of local variable x + * and passes it to this function. This prevents the compiler + * from caching the value across function calls. + * This is needed for situations where + * - a compiler caches a variable in a register, but not entirely (the variable + * has a backing memory location); and + * - that location contains a stale old value of the variable, which cannot be + * garbage-collected as a result; and + * - this causes a problem, like unbounded memory growth. + */ +void gc_hint_func(val *val) +{ + (void) val; +} diff --git a/gc.h b/gc.h index 760f7f1f..d2fa038d 100644 --- a/gc.h +++ b/gc.h @@ -34,3 +34,5 @@ int gc_state(int); void gc_mark(val); int gc_is_reachable(val); void unmark(void); +void gc_hint_func(val *); +#define gc_hint(var) gc_hint_func(&var) diff --git a/match.c b/match.c index 04554cff..85e65cf0 100644 --- a/match.c +++ b/match.c @@ -874,6 +874,8 @@ static val match_files(val spec, val files, val data = nil; cnum data_lineno = 0; + gc_hint(data); + if (listp(first_file_parsed)) { data = first_file_parsed; data_lineno = c_num(data_linenum); -- cgit v1.2.3