]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix the strdup-of-OverlapErr-string problem better. Move the
authorJulian Seward <jseward@acm.org>
Thu, 24 Jul 2003 23:50:17 +0000 (23:50 +0000)
committerJulian Seward <jseward@acm.org>
Thu, 24 Jul 2003 23:50:17 +0000 (23:50 +0000)
strdup to MAC_(record_overlap_error), wherein we know that
s is a string.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1786

coregrind/vg_errcontext.c
memcheck/mac_needs.c

index ca5b7f7703a1daa05e450b5ed95ab379f41859b8..19f86ff4877b3bd58ba9b7a1622eedeee6fad2ce 100644 (file)
@@ -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;
index 17ad8a6ba58a595ca02ca20bb5d60802dbc317bf..21e3a1f6b7188e5d7032199ef95a688e9c50b1d8 100644 (file)
@@ -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 );
 }