From: Julian Seward Date: Thu, 24 Jul 2003 21:29:40 +0000 (+0000) Subject: construct_error(): strdup the supplied s (string) param which gives X-Git-Tag: svn/VALGRIND_2_0_0~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2e724ba3dfce02d337fa46bb38a60e2472afc5c0;p=thirdparty%2Fvalgrind.git construct_error(): strdup the supplied s (string) param which gives extra info about some kinds of errors. It was being allocated on the stack by complain2/3 in mac_malloc_wrappers.c. If the constructed error is found to be a duplicate, free the strdup'd space. That limits the worst-case space leak to one strdup'd string for each different error we keep track of, and the latter by default is limited to 300. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1785 --- diff --git a/coregrind/vg_errcontext.c b/coregrind/vg_errcontext.c index 700e4c67a1..ca5b7f7703 100644 --- a/coregrind/vg_errcontext.c +++ b/coregrind/vg_errcontext.c @@ -184,9 +184,13 @@ void construct_error ( Error* err, ThreadId tid, ErrorKind ekind, Addr a, /* Skin-relevant parts */ err->ekind = ekind; err->addr = a; - err->string = s; err->extra = extra; - + if (s) { + err->string = VG_(arena_strdup)( VG_AR_ERRORS, s ); + } + else { + err->string = NULL; + } /* sanity... */ vg_assert( tid < VG_N_THREADS ); } @@ -341,6 +345,7 @@ 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. */ @@ -366,6 +371,13 @@ void VG_(maybe_record_error) ( ThreadId tid, p->next = vg_errors; 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;