From: Julian Seward Date: Thu, 24 Jul 2003 23:50:17 +0000 (+0000) Subject: Fix the strdup-of-OverlapErr-string problem better. Move the X-Git-Tag: svn/VALGRIND_2_0_0~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ffbedad97e09aecc2761182a95a5de069480af2e;p=thirdparty%2Fvalgrind.git Fix the strdup-of-OverlapErr-string problem better. Move the strdup to MAC_(record_overlap_error), wherein we know that s is a string. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1786 --- diff --git a/coregrind/vg_errcontext.c b/coregrind/vg_errcontext.c index ca5b7f7703..19f86ff487 100644 --- a/coregrind/vg_errcontext.c +++ b/coregrind/vg_errcontext.c @@ -185,12 +185,8 @@ void construct_error ( Error* err, ThreadId tid, ErrorKind ekind, Addr a, err->ekind = ekind; err->addr = a; err->extra = extra; - if (s) { - err->string = VG_(arena_strdup)( VG_AR_ERRORS, s ); - } - else { - err->string = NULL; - } + err->string = s; + /* sanity... */ vg_assert( tid < VG_N_THREADS ); } @@ -345,7 +341,6 @@ void VG_(maybe_record_error) ( ThreadId tid, } /* Build ourselves the error */ - err.string = NULL; construct_error ( &err, tid, ekind, a, s, extra, NULL ); /* First, see if we've got an error record matching this one. */ @@ -372,12 +367,6 @@ void VG_(maybe_record_error) ( ThreadId tid, vg_errors = p; } - /* Free err.string, if we allocated it. */ - if (err.string) { - VG_(arena_free)( VG_AR_ERRORS, err.string ); - err.string = NULL; /* paranoia */ - } - return; } p_prev = p; diff --git a/memcheck/mac_needs.c b/memcheck/mac_needs.c index 17ad8a6ba5..21e3a1f6b7 100644 --- a/memcheck/mac_needs.c +++ b/memcheck/mac_needs.c @@ -472,11 +472,21 @@ void MAC_(record_freemismatch_error) ( ThreadId tid, Addr a ) // This one not passed a ThreadId, so it grabs it itself. void MAC_(record_overlap_error) ( Char* function ) { + static Int n_strdups = 0; MAC_Error err_extra; + + /* Potential space leak; this strdup'd space is never + reclaimed. Hence hacky sanity check. */ + if (n_strdups < 1000) { + n_strdups++; + function = VG_(strdup) ( function ); + } else { + function = NULL; + } MAC_(clear_MAC_Error)( &err_extra ); VG_(maybe_record_error)( VG_(get_current_or_recent_tid)(), - OverlapErr, /*addr*/0, function, &err_extra ); + OverlapErr, /*addr*/0, /*s*/function, &err_extra ); }