Use boost::scoped_array to manage working buffer for RAII in Session::import_audiofile
authorTim Mayberry <mojofunk@gmail.com>
Thu, 15 Nov 2007 02:31:19 +0000 (02:31 +0000)
committerTim Mayberry <mojofunk@gmail.com>
Thu, 15 Nov 2007 02:31:19 +0000 (02:31 +0000)
git-svn-id: svn://localhost/ardour2/trunk@2658 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/import.cc

index f0d38929997bee54fb6103d63f5316771b13150d..94bb309e75c5eb12731bd4bca90e2ff5e4ff0590 100644 (file)
@@ -31,6 +31,8 @@
 
 #include <glibmm.h>
 
+#include <boost/scoped_array.hpp>
+
 #include <pbd/basename.h>
 #include <pbd/convert.h>
 
@@ -94,7 +96,6 @@ Session::import_audiofile (import_status& status)
 {
        vector<boost::shared_ptr<AudioFileSource> > newfiles;
        SF_INFO info;
-       float *data = 0;
        Sample **channel_data = 0;
        int nfiles = 0;
        string basepath;
@@ -154,8 +155,8 @@ Session::import_audiofile (import_status& status)
                        newfiles[n]->prepare_for_peakfile_writes ();
                        nfiles++;
                }
-       
-               data = new float[nframes * info.channels];
+
+               boost::scoped_array<float> data(new float[nframes * info.channels]);
                channel_data = new Sample * [ info.channels ];
        
                for (int n = 0; n < info.channels; ++n) {
@@ -186,7 +187,7 @@ Session::import_audiofile (import_status& status)
                        long x;
                        long chn;
                
-                       if ((nread = importable->read (data, nframes)) == 0) {
+                       if ((nread = importable->read (data.get(), nframes)) == 0) {
                                break;
                        }
                        nfread = nread / info.channels;
@@ -246,10 +247,6 @@ Session::import_audiofile (import_status& status)
        ret = 0;
 
   out:
-
-       if (data) {
-               delete [] data;
-       }
        
        if (channel_data) {
                for (int n = 0; n < info.channels; ++n) {