Use boost::scoped_array in AudioSource::build_peaks_from_scratch
authorPaul Davis <paul@linuxaudiosystems.com>
Sat, 13 Jul 2013 21:43:36 +0000 (17:43 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Sat, 13 Jul 2013 21:43:36 +0000 (17:43 -0400)
libs/ardour/audiosource.cc

index c9b80e7a5c7813bc65c38b6342268b9c8235d59d..30c1852de30d462b0180e23d84c64436018f8a9e 100644 (file)
@@ -584,8 +584,6 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, framecnt_t npeaks, framepos_t
 int
 AudioSource::build_peaks_from_scratch ()
 {
-       Sample* buf = 0;
-
        const framecnt_t bufsize = 65536; // 256kB per disk read for mono data is about ideal
 
        DEBUG_TRACE (DEBUG::Peaks, "Building peaks from scratch\n");
@@ -605,20 +603,20 @@ AudioSource::build_peaks_from_scratch ()
                framecnt_t cnt = _length;
 
                _peaks_built = false;
-               buf = new Sample[bufsize];
+               boost::scoped_array<Sample> buf(new Sample[bufsize]);
 
                while (cnt) {
 
                        framecnt_t frames_to_read = min (bufsize, cnt);
                        framecnt_t frames_read;
                        
-                       if ((frames_read = read_unlocked (buf, current_frame, frames_to_read)) != frames_to_read) {
+                       if ((frames_read = read_unlocked (buf.get(), current_frame, frames_to_read)) != frames_to_read) {
                                error << string_compose(_("%1: could not write read raw data for peak computation (%2)"), _name, strerror (errno)) << endmsg;
                                done_with_peakfile_writes (false);
                                goto out;
                        }
 
-                       if (compute_and_write_peaks (buf, current_frame, frames_read, true, false, _FPP)) {
+                       if (compute_and_write_peaks (buf.get(), current_frame, frames_read, true, false, _FPP)) {
                                break;
                        }
 
@@ -643,8 +641,6 @@ AudioSource::build_peaks_from_scratch ()
                unlink (peakpath.c_str());
        }
 
-       delete [] buf;
-
        return ret;
 }