construct_error(): strdup the supplied s (string) param which gives
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 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/vg_errcontext.c b/coregrind/vg_errcontext.c
index 700e4c6..ca5b7f7 100644
--- a/coregrind/vg_errcontext.c
+++ b/coregrind/vg_errcontext.c
@@ -184,9 +184,13 @@
    /* 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 @@
    }
 
    /* 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 @@
             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;