Description: Modify data loading memory management to avoid crashes.
This patch fixes a crash in audsp in Festival and other
memory leaks.
Bug: #601294
Author: Samuel Thibault.
Applied-Upstream: https://github.com/festvox/speech_tools/pull/7

--- a/base_class/rateconv.cc
+++ b/base_class/rateconv.cc
@@ -431,7 +431,7 @@ static int outmax;
 
 static int ioerr(void)
 {
-    delete g_coep;
+    delete[] g_coep;
     return -1;
 }
 
@@ -585,7 +585,7 @@ int rateconv(short *in,int isize, short
 	    return ioerr();
     } while (outsize == OUTBUFFSIZE); 
 
-    delete g_coep;
+    delete[] g_coep;
 
     *osize = outpos;
 
--- a/base_class/string/EST_String.cc
+++ b/base_class/string/EST_String.cc
@@ -329,6 +329,7 @@ int EST_String::gsub_internal (const cha
 	  p += length;
 	  at=end;
 	}
+   if (p != from+at)
       memcpy(p, from+at, size-at);
 
       p += size-at;
--- a/speech_class/EST_WaveFile.cc
+++ b/speech_class/EST_WaveFile.cc
@@ -90,7 +90,10 @@ EST_read_status load_using(standard_load
 
   if (status == read_ok)
     {
-      wv.values().set_memory(data, 0, nsamp, nchan, TRUE);
+      short *data2 = new short[nsamp*nchan];
+      memcpy(data2, data, nsamp*nchan*sizeof(short));
+      wfree(data);
+      wv.values().set_memory(data2, 0, nsamp, nchan, TRUE);
       wv.set_sample_rate(srate);
     }
 
