]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
construct_error(): strdup the supplied s (string) param which gives
authorJulian Seward <jseward@acm.org>
Thu, 24 Jul 2003 21:29:40 +0000 (21:29 +0000)
committerJulian Seward <jseward@acm.org>
Thu, 24 Jul 2003 21:29:40 +0000 (21:29 +0000)
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

coregrind/vg_errcontext.c

index 700e4c67a1a4aa8a535aab66e843a353f887fb7c..ca5b7f7703a1daa05e450b5ed95ab379f41859b8 100644 (file)
@@ -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;