diff --git a/ChangeLog b/ChangeLog index 836e15c2df..1c4ff64fe8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Aug 19 13:31:40 2007 Tanaka Akira + + * gc.c: use VALGRIND_MAKE_MEM_UNDEFINED to detect use of collected + objects if valgrind is available. It cannot detect first 2 words + because they are used as the free list. + Sun Aug 19 13:13:52 2007 Koichi Sasada * compile.c (iseq_compile_each/NODE_RESBODY): fix to add diff --git a/gc.c b/gc.c index f187b06820..a9683e7493 100644 --- a/gc.c +++ b/gc.c @@ -40,8 +40,12 @@ # ifndef VALGRIND_MAKE_MEM_DEFINED # define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE(p, n) # endif +# ifndef VALGRIND_MAKE_MEM_UNDEFINED +# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE(p, n) +# endif #else # define VALGRIND_MAKE_MEM_DEFINED(p, n) /* empty */ +# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) /* empty */ #endif int rb_io_fptr_finalize(struct rb_io_t*); @@ -1099,6 +1103,7 @@ finalize_list(RVALUE *p) RVALUE *tmp = p->as.free.next; run_final((VALUE)p); if (!FL_TEST(p, FL_SINGLETON)) { /* not freeing page */ + VALGRIND_MAKE_MEM_UNDEFINED((void*)p, sizeof(RVALUE)); p->as.free.flags = 0; p->as.free.next = freelist; freelist = p; @@ -1168,6 +1173,7 @@ gc_sweep(void) final_list = p; } else { + VALGRIND_MAKE_MEM_UNDEFINED((void*)p, sizeof(RVALUE)); p->as.free.flags = 0; p->as.free.next = freelist; freelist = p; @@ -1218,6 +1224,7 @@ gc_sweep(void) void rb_gc_force_recycle(VALUE p) { + VALGRIND_MAKE_MEM_UNDEFINED((void*)p, sizeof(RVALUE)); RANY(p)->as.free.flags = 0; RANY(p)->as.free.next = freelist; freelist = RANY(p); @@ -2001,10 +2008,12 @@ rb_gc_call_finalizer_at_exit(void) else if (RANY(p)->as.data.dfree) { (*RANY(p)->as.data.dfree)(DATA_PTR(p)); } + VALGRIND_MAKE_MEM_UNDEFINED((void*)p, sizeof(RVALUE)); } else if (BUILTIN_TYPE(p) == T_FILE) { if (rb_io_fptr_finalize(RANY(p)->as.file.fptr)) { p->as.free.flags = 0; + VALGRIND_MAKE_MEM_UNDEFINED((void*)p, sizeof(RVALUE)); } } p++;