From: Florian Krohm Date: Wed, 18 Sep 2013 14:00:10 +0000 (+0000) Subject: Fix memory leak when reallocating a thread name. X-Git-Tag: svn/VALGRIND_3_9_0~130 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ac9cb1d0cb3dacf6a86b2ca1467083c054f5455;p=thirdparty%2Fvalgrind.git Fix memory leak when reallocating a thread name. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13561 --- diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c index f0fb675239..73a4ab5ce4 100644 --- a/coregrind/m_scheduler/scheduler.c +++ b/coregrind/m_scheduler/scheduler.c @@ -238,7 +238,9 @@ ThreadId VG_(alloc_ThreadState) ( void ) if (VG_(threads)[i].status == VgTs_Empty) { VG_(threads)[i].status = VgTs_Init; VG_(threads)[i].exitreason = VgSrc_None; - VG_(threads)[i].thread_name = NULL; + if (VG_(threads)[i].thread_name) + VG_(arena_free)(VG_AR_CORE, VG_(threads)[i].thread_name); + VG_(threads)[i].thread_name = NULL; return i; } } diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index bf515d98e6..ed72309fa0 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -951,10 +951,13 @@ POST(sys_prctl) const HChar* new_name = (const HChar*) ARG2; if (new_name) { // Paranoia ThreadState* tst = VG_(get_ThreadState)(tid); + SizeT new_len = VG_(strlen)(new_name); /* Don't bother reusing the memory. This is a rare event. */ tst->thread_name = - VG_(arena_strdup)(VG_AR_CORE, "syswrap.prctl", new_name); + VG_(arena_realloc)(VG_AR_CORE, "syswrap.prctl", + tst->thread_name, new_len + 1); + VG_(strcpy)(tst->thread_name, new_name); } } break;