|
From: <sv...@va...> - 2013-09-18 14:00:24
|
Author: florian
Date: Wed Sep 18 14:00:10 2013
New Revision: 13561
Log:
Fix memory leak when reallocating a thread name.
Modified:
trunk/coregrind/m_scheduler/scheduler.c
trunk/coregrind/m_syswrap/syswrap-linux.c
Modified: trunk/coregrind/m_scheduler/scheduler.c
==============================================================================
--- trunk/coregrind/m_scheduler/scheduler.c (original)
+++ trunk/coregrind/m_scheduler/scheduler.c Wed Sep 18 14:00:10 2013
@@ -238,7 +238,9 @@
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;
}
}
Modified: trunk/coregrind/m_syswrap/syswrap-linux.c
==============================================================================
--- trunk/coregrind/m_syswrap/syswrap-linux.c (original)
+++ trunk/coregrind/m_syswrap/syswrap-linux.c Wed Sep 18 14:00:10 2013
@@ -951,10 +951,13 @@
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;
|