]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix memory leak when reallocating a thread name.
authorFlorian Krohm <florian@eich-krohm.de>
Wed, 18 Sep 2013 14:00:10 +0000 (14:00 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Wed, 18 Sep 2013 14:00:10 +0000 (14:00 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13561

coregrind/m_scheduler/scheduler.c
coregrind/m_syswrap/syswrap-linux.c

index f0fb675239644fbb72ffbbb28a249f7a7ad1ea5d..73a4ab5ce4c21bc2004aa0589fb0342acbe9dbea 100644 (file)
@@ -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;
       }
    }
index bf515d98e6a6f16eb37f38cffb7b59c6b6e8930c..ed72309fa08611fd927e9019d3bfe2012d0ec9ad 100644 (file)
@@ -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;