Resolve regressions in full test suite.

More naming of temporaries so they can be bound to ref formals.

Check for and plug leaks:
diff --git a/modules/internal/ChapelIO.chpl b/modules/internal/ChapelIO.chpl
index 208e4c3..316b871 100644
--- a/modules/internal/ChapelIO.chpl
+++ b/modules/internal/ChapelIO.chpl
@@ -603,8 +603,10 @@ module ChapelIO {
   proc format(fmt: c_string, x:?t) where isIntegralType(t) || isFloatType(t) {
     if fmt.substring(1) == "#" {
       var fmt2 = _getoutputformat(fmt);
-      if isImagType(t) then
-        return (chpl_format(fmt2, _i2r(x))+"i");
+      if isImagType(t) {
+        var resb = chpl_format(fmt2, _i2r(x));
+        return (resb+"i");
+      }
       else
         return chpl_format(fmt2, x:real);
     } else
@@ -614,7 +616,11 @@ module ChapelIO {
   proc format(fmt: c_string, x:?t) where isComplexType(t) {
     if fmt.substring(1) == "#" {
       var fmt2 = _getoutputformat(fmt);
-      return (chpl_format(fmt2, x.re)+" + "+ chpl_format(fmt2, x.im)+"i");
+      var fmt_r = chpl_format(fmt2, x.re);
+      var fmt_i = chpl_format(fmt2, x.im);
+      var fmt_i_i = fmt_i + "i";
+      var res1 = fmt_r + " + ";
+      return res1 + fmt_i_i;
     } else
       return chpl_format(fmt, x);
   }
diff --git a/modules/standard/Error.chpl b/modules/standard/Error.chpl
index e0e25a6..36e25a1 100644
--- a/modules/standard/Error.chpl
+++ b/modules/standard/Error.chpl
@@ -100,17 +100,9 @@ proc ioerror(errstr:string, msg:string, path:string, offset:int(64))
 {
   var quotedpath:c_string;
   quotedpath = quote_string(path, path.length:ssize_t);
-  // Intermediate concatenations consume their c_string_copy args.
-  var errstr_s = errstr + " ";
-  var errstr_s_m = errstr_s + msg.c_str();
-  var errstr_s_m_w = errstr_s_m + " with path ";
-  var errstr_s_m_w_q = errstr_s_m_w + quotedpath;
-  var errstr_s_m_w_q_o = errstr_s_m_w_q + " offset ";
-  var offset_cstr = offset:c_string_copy;
-  var errstr_s_m_w_q_o_o = errstr_s_m_w_q_o + offset_cstr;
-  __primitive("chpl_error", errstr_s_m_w_q_o_o);
-    // But the last one must be freed explicitly.
-  chpl_free_c_string_copy(errstr_s_m_w_q_o_o);
+  // TODO: Because the output of concatenation (+) is an allocated string,
+  // this routine leaks like a sieve.
+  __primitive("chpl_error", errstr + " " + msg.c_str() + " with path " + quotedpath + " offset " + offset:c_string_copy);
 }

 proc errorToString(error:syserr):string
diff --git a/modules/standard/Regexp.chpl b/modules/standard/Regexp.chpl
index 54a80ef..7867564 100644
--- a/modules/standard/Regexp.chpl
+++ b/modules/standard/Regexp.chpl
@@ -80,7 +80,9 @@ proc compile(pattern: string, utf8=true, posix=false, literal=false, nocapture=f
   qio_regexp_create_compile(pattern.c_str(), pattern.length, opts, ret._regexp);
   if ! qio_regexp_ok(ret._regexp) {
     var err_str = qio_regexp_error(ret._regexp);
-    __primitive("chpl_error", "Error " + err_str + " when compiling regexp '" + pattern + "'");
+    var err_str_p = "Error " + err_str;
+    var err_str_p_w = err_str_p + " when compiling regexp '";
+    __primitive("chpl_error", err_str_p_w + pattern + "'");
   }
   return ret;
 }
diff --git a/test/distributions/dm/u.chpl b/test/distributions/dm/u.chpl
index 2948278..70eb865 100644
--- a/test/distributions/dm/u.chpl
+++ b/test/distributions/dm/u.chpl
@@ -5,14 +5,19 @@ use DimensionalDist2D;

 /// label the output with "phases" //////////////////////////////////////////

-var pfx = "# ";
+var pfx:c_string_copy = "# ";
 var phase = 0;
 var no_pfx = false;

 // to preserve coarse ordering ("phases") when sorting the output
 proc nextphase() {
   phase += 1;
-  pfx = if no_pfx then "" else format("####", phase) + "  ";
+  if no_pfx
+    then pfx = "";
+    else {
+      var p_fmt = format("####", phase);
+      pfx = p_fmt + "  ";
+    }
   traceDimensionalDistPrefix = pfx;
 }

diff --git a/test/studies/amr/advection/amr/AMRHierarchy_AdvectionCTU.chpl b/test/studies/amr/advection/amr/AMRHierarchy_AdvectionCTU.chpl
index c0bdb64..bf29315 100644
--- a/test/studies/amr/advection/amr/AMRHierarchy_AdvectionCTU.chpl
+++ b/test/studies/amr/advection/amr/AMRHierarchy_AdvectionCTU.chpl
@@ -24,10 +24,13 @@ proc AMRHierarchy.advance_AdvectionCTU(
 {

   //---- Safety check ----
+  var timef = format("%8.4E",time);
+  var ptimef = "AMRHierarchy.time = " + timef;
+  var pptimef = "error: AMRHierarchy.advance_AdvectionCTU\n" + ptimef;
+  var timereqf = format("%8.4E",time_requested);
+  var ptimereqf = ", while time_requested = " + timereqf;
   assert(time < time_requested,
-         "error: AMRHierarchy.advance_AdvectionCTU\n" +
-         "AMRHierarchy.time = " + format("%8.4E",time) + ", while time_requested = " +
-         format("%8.4E",time_requested));
+         pptimef + ptimereqf);

   //---- Set dt_target ----
diff --git a/test/studies/amr/advection/amr/AMR_AdvectionCTU_driver.chpl b/test/studies/amr/advection/amr/AMR_AdvectionCTU_driver.chpl
index cf2242e..fa31050 100644
--- a/test/studies/amr/advection/amr/AMR_AdvectionCTU_driver.chpl
+++ b/test/studies/amr/advection/amr/AMR_AdvectionCTU_driver.chpl
@@ -174,8 +174,9 @@ proc main {
   write("Writing initial output...");
   hierarchy.clawOutput(frame_number);
   write("done.\n");
-
-  writeln("Current time of AMRHierarchy: " + format("%8.4E",hierarchy.time));
+
+  var timef = format("%8.4E",hierarchy.time);
+  writeln("Current time of AMRHierarchy: " + timef);

   //---- Subsequent outputs ----
diff --git a/test/studies/amr/advection/level/Level_AdvectionCTU_driver.chpl b/test/studies/amr/advection/level/Level_AdvectionCTU_driver.chpl
index 6bee822..ebbbfc0 100644
--- a/test/studies/amr/advection/level/Level_AdvectionCTU_driver.chpl
+++ b/test/studies/amr/advection/level/Level_AdvectionCTU_driver.chpl
@@ -44,8 +44,9 @@ proc main {
   var phys_file = open("set_problem/physics.txt", iomode.r).reader();
   var dim_in: int;
   phys_file.readln(dim_in);
+  var dimf = format("%i",dimension);
   assert(dim_in == dimension,
-         "error: dimension of physics.txt must equal " + format("%i",dimension));
+         "error: dimension of physics.txt must equal " + dimf);
   phys_file.readln((...velocity));
   phys_file.close();
   //<=== Advection velocity <===
diff --git a/test/studies/amr/lib/cfboundary/RefiningTransfer.chpl b/test/studies/amr/lib/cfboundary/RefiningTransfer.chpl
index c489e58..06cb4e3 100644
--- a/test/studies/amr/lib/cfboundary/RefiningTransfer.chpl
+++ b/test/studies/amr/lib/cfboundary/RefiningTransfer.chpl
@@ -555,13 +555,20 @@ proc GridVariable.fillCFGhostRegion (

   //==== Make sure that t1 < time < t2, with small margin for roundoff error ====
-  assert(time > t1 - 1.0E-8  &&  time < t2 + 1.0E-8,
-	 "Warning: LevelVariable.getFineBoundaryValues\n" +
-	 "Requesting fine data at time " + format("%8.4E",time) + "\n" +
-	 "coarse_overlap_solution.old_time =     " + format("%8.4E", t1) + "\n" +
-	 "coarse_overlap_solution.current_time = " + format("%8.4E", t2));
-
-
+  var timef = format("%8.4E",time);
+  var time1f = format("%8.4E", t1);
+  var time2f = format("%8.4E", t2);
+  var ptimef = "Requesting fine data at time " + timef;
+  var pptimef = "Warning: LevelVariable.getFineBoundaryValues\n" + ptimef;
+  var pptimefl = pptimef + "\n";
+  var ptime1f = "coarse_overlap_solution.old_time =     " + time1f;
+  var ptime1fl = ptime1f + "\n";
+  var ptime2f = "coarse_overlap_solution.current_time = " + time2f;
+  var msg1 = pptimefl + ptime1fl;
+  var msg2 = msg1 + ptime2f;
+  assert(time > t1 - 1.0E-8  &&  time < t2 + 1.0E-8, msg2);
+  chpl_free_c_string_copy(msg2);
+
   //==== Interpolate ====
   const c2 = (time - t1) / (t2 - t1);
   const c1 = 1 - c2;
diff --git a/test/studies/amr/lib/grid/GridVariable_def.chpl b/test/studies/amr/lib/grid/GridVariable_def.chpl
index 06ec6ea..2dcf2aa 100644
--- a/test/studies/amr/lib/grid/GridVariable_def.chpl
+++ b/test/studies/amr/lib/grid/GridVariable_def.chpl
@@ -166,7 +166,11 @@ proc GridVariable.writeData (
       when 1 do linelabel = "                 mx";
       when 2 do linelabel = "                 my";
       when 3 do linelabel = "                 mz";
-      otherwise linelabel = "                 mx(" + format("%1i",d) + ")";
+      otherwise {
+        var dimf = format("%1i",d);
+        var ldimf = "                 mx(" + dimf;
+        linelabel = ldimf + ")";
+      }
     }
     outfile.writeln( format(ifmt, grid.n_cells(d)),  linelabel);
   }
@@ -178,7 +182,11 @@ proc GridVariable.writeData (
       when 1 do linelabel = "    xlow";
       when 2 do linelabel = "    ylow";
       when 3 do linelabel = "    zlow";
-      otherwise linelabel = "    xlow(" + format("%1i",d) + ")";
+      otherwise {
+        var dimf = format("%1i",d);
+        var ldimf = "    xlow(" + dimf;
+        linelabel = ldimf + ")";
+      }
     }
     outfile.writeln( format(efmt, grid.x_low(d)),  linelabel);
   }
@@ -190,7 +198,11 @@ proc GridVariable.writeData (
       when 1 do linelabel = "    dx";
       when 2 do linelabel = "    dy";
       when 3 do linelabel = "    dz";
-      otherwise linelabel = "    dx(" + format("%1i",d) + ")";
+      otherwise {
+        var dimf = format("%1i",d);
+        var ldimf = "    dx(" + dimf;
+        linelabel = ldimf + ")";
+      }
     }
     outfile.writeln( format(efmt, grid.dx(d)),  linelabel);
   }
diff --git a/test/studies/amr/lib/grid/Grid_def.chpl b/test/studies/amr/lib/grid/Grid_def.chpl
index 13dedb4..3f4b817 100644
--- a/test/studies/amr/lib/grid/Grid_def.chpl
+++ b/test/studies/amr/lib/grid/Grid_def.chpl
@@ -285,8 +285,10 @@ proc readGrid(file_name: string) {

   var dim_in: int;
   input_file.readln(dim_in);
+  var dimf = format("%i",dimension);
   assert(dim_in == dimension,
-         "error: dimension of space.txt must equal " + format("%i",dimension));
+         "error: dimension of space.txt must equal " + dimf);
+  chpl_free_c_string_copy(dimf);
   input_file.readln(); // empty line

   var x_low, x_high:                 dimension*real;
diff --git a/test/studies/amr/lib/level/Level_def.chpl b/test/studies/amr/lib/level/Level_def.chpl
index 94e2cf7..355025b 100644
--- a/test/studies/amr/lib/level/Level_def.chpl
+++ b/test/studies/amr/lib/level/Level_def.chpl
@@ -453,8 +453,9 @@ proc readLevel(file_name: string){

   var dim_in: int;
   input_file.readln(dim_in);
+  var dimf = format("%i",dimension);
   assert(dim_in == dimension,
-         "error: dimension of space.txt must equal " + format("%i",dimension));
+         "error: dimension of space.txt must equal " + dimf);
   input_file.readln(); // empty line

   var x_low, x_high:    dimension*real;
diff --git a/test/types/range/vass/range-follower-multi.chpl b/test/types/range/vass/range-follower-multi.chpl
index 1ca9bb3..c58dada 100644
--- a/test/types/range/vass/range-follower-multi.chpl
+++ b/test/types/range/vass/range-follower-multi.chpl
@@ -1,12 +1,16 @@
 /////////////////////////////////
-var pfx = "# ";
+var pfx:c_string_copy = "# ";
 var phase = 0;
 var no_pfx = false;

 // to preserve coarse ordering ("phases") when sorting the output
 proc nextphase() {
   phase += 1;
-  pfx = if no_pfx then "" else format("####", phase) + "  ";
+  if no_pfx then pfx = "";
+  else {
+    var fmt_p = format("####", phase);
+    pfx = fmt_p + "  ";
+  }
 }

 // Force the next phase to be 'ph' - so that when phases are added earlier,
diff --git a/test/types/range/vass/range-follower-multi.good b/test/types/range/vass/range-follower-multi.good
index a941470..c82ae24 100644
--- a/test/types/range/vass/range-follower-multi.good
+++ b/test/types/range/vass/range-follower-multi.good
@@ -117,4 +117,4 @@
  401  (4, 4)
  401  it * it
  402  it * r
-range-follower-multi.chpl:64: error: halt reached - zippered iteration with a range has non-equal lengths
+range-follower-multi.chpl:68: error: halt reached - zippered iteration with a range has non-equal lengths
diff --git a/test/users/vass/crash4replLclsWFlds.chpl b/test/users/vass/crash4replLclsWFlds.chpl
index 4b312f6..862061c 100644
--- a/test/users/vass/crash4replLclsWFlds.chpl
+++ b/test/users/vass/crash4replLclsWFlds.chpl
@@ -1405,13 +1405,14 @@ iter sdom.dsiFollowerArrayIterator1d(denseRange) {

 /// label the output with "phases" //////////////////////////////////////////

-var pfx = "# ";
+var pfx:c_string_copy = "# ";
 var phase = 0;

 // to preserve coarse ordering ("phases") when sorting the output
 proc nextphase() {
   phase += 1;
-  pfx = format("####", phase) + "  ";
+  var fmt_p = format("####", phase);
+  pfx = fmt_p + "  ";
   traceDimensionalDistPrefix = pfx;
 }