changeset 1402:aadfb395e933

Fix some one-off memory leaks (including distracting ones in tests)
author Chris Cannam
date Mon, 06 Mar 2017 17:37:23 +0000
parents cc62d7862203
children edee37ae5882
files data/fileio/AudioFileSizeEstimator.cpp data/fileio/MP3FileReader.cpp data/fileio/test/AudioFileReaderTest.h data/fileio/test/EncodingTest.h data/midi/rtmidi/RtMidi.cpp
diffstat 5 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/AudioFileSizeEstimator.cpp	Mon Mar 06 17:23:46 2017 +0000
+++ b/data/fileio/AudioFileSizeEstimator.cpp	Mon Mar 06 17:37:23 2017 +0000
@@ -42,7 +42,6 @@
         if (targetRate != 0.0 && targetRate != rate) {
             samples = sv_frame_t(double(samples) * targetRate / rate);
         }
-        delete reader;
         SVDEBUG << "AudioFileSizeEstimator: WAV file reader accepts this file, reports "
                 << samples << " samples" << endl;
         estimate = samples;
@@ -51,6 +50,9 @@
                 << "estimating from file size and extension instead" << endl;
     }
 
+    delete reader;
+    reader = 0;
+
     if (estimate == 0) {
 
         // The remainder just makes an estimate based on the file size
--- a/data/fileio/MP3FileReader.cpp	Mon Mar 06 17:23:46 2017 +0000
+++ b/data/fileio/MP3FileReader.cpp	Mon Mar 06 17:37:23 2017 +0000
@@ -136,6 +136,14 @@
         if (!decode(m_fileBuffer, m_fileBufferSize)) {
             m_error = QString("Failed to decode file %1.").arg(m_path);
         }
+
+        if (m_sampleBuffer) {
+            for (int c = 0; c < m_channelCount; ++c) {
+                delete[] m_sampleBuffer[c];
+            }
+            delete[] m_sampleBuffer;
+            m_sampleBuffer = 0;
+        }
         
         delete[] m_fileBuffer;
         m_fileBuffer = 0;
--- a/data/fileio/test/AudioFileReaderTest.h	Mon Mar 06 17:23:46 2017 +0000
+++ b/data/fileio/test/AudioFileReaderTest.h	Mon Mar 06 17:37:23 2017 +0000
@@ -287,6 +287,10 @@
 	// expected number back (if this is not mp3/aac) or (b) take
 	// into account silence at beginning and end (if it is).
 	floatvec_t test = reader->getInterleavedFrames(0, refFrames + 5000);
+
+        delete reader;
+        reader = 0;
+        
 	sv_frame_t read = test.size() / channels;
 
         bool perceptual = (extension == "mp3" ||
--- a/data/fileio/test/EncodingTest.h	Mon Mar 06 17:23:46 2017 +0000
+++ b/data/fileio/test/EncodingTest.h	Mon Mar 06 17:37:23 2017 +0000
@@ -107,6 +107,8 @@
             (encodingDir + "/" + audiofile, params);
 
         QVERIFY(reader != nullptr);
+
+        delete reader;
     }
 
     void readMetadata_data() {
@@ -132,7 +134,13 @@
         QString file = fileAndExt[0];
         QString extension = fileAndExt[1];
 
-        if (extension != "wav") {
+        if (extension == "wav") {
+
+            // Nothing
+            
+            delete reader;
+
+        } else {
 
 #if (!defined (HAVE_OGGZ) || !defined(HAVE_FISHSOUND))
             if (extension == "ogg") {
@@ -145,6 +153,8 @@
             QString title = reader->getTitle();
             QVERIFY(title != QString());
 
+            delete reader;
+
             bool found = false;
             for (int m = 0; m < mappingCount; ++m) {
                 if (file == QString::fromUtf8(mapping[m][0])) {
--- a/data/midi/rtmidi/RtMidi.cpp	Mon Mar 06 17:23:46 2017 +0000
+++ b/data/midi/rtmidi/RtMidi.cpp	Mon Mar 06 17:37:23 2017 +0000
@@ -39,6 +39,9 @@
 #include "RtMidi.h"
 #include <sstream>
 
+// CC be gung-ho about this here, assume upstream has it in hand
+#pragma GCC diagnostic ignored "-Wconversion"
+
 #if defined(__MACOSX_CORE__)
   #if TARGET_OS_IPHONE
     #define AudioGetCurrentHostTime CAHostTimeBase::GetCurrentTime