diff --git a/libs/audiographer/audiographer/sndfile/tmp_file.h b/libs/audiographer/audiographer/sndfile/tmp_file.h index facb872abf..5b5b748a64 100644 --- a/libs/audiographer/audiographer/sndfile/tmp_file.h +++ b/libs/audiographer/audiographer/sndfile/tmp_file.h @@ -35,7 +35,10 @@ class TmpFile : public SndfileWriter, public SndfileReader ~TmpFile() { if (!filename.empty()) { - std::remove(filename.c_str()); + SndfileHandle::close(); + if (std::remove(filename.c_str() ) != 0) { + std::cout << "TmpFile::~TmpFile () : Error removing temp file: " << strerror(errno) << std::endl; + } } } diff --git a/libs/audiographer/private/sndfile.hh b/libs/audiographer/private/sndfile.hh index 1c4ef5ab58..a7d887003f 100644 --- a/libs/audiographer/private/sndfile.hh +++ b/libs/audiographer/private/sndfile.hh @@ -94,6 +94,8 @@ class SndfileHandle bool operator == (const SndfileHandle &rhs) const { return (p == rhs.p) ; } + int close (void); + sf_count_t frames (void) const { return p ? p->sfinfo.frames : 0 ; } int format (void) const { return p ? p->sfinfo.format : 0 ; } int channels (void) const { return p ? p->sfinfo.channels : 0 ; } @@ -250,6 +252,20 @@ SndfileHandle::operator = (const SndfileHandle &rhs) return *this ; } /* SndfileHandle assignment operator */ +int +SndfileHandle::close (void) +{ + if ( (p->sf != NULL) && (sf_close (p->sf) == 0 ) ) + { + p->sf = NULL; + return 0; + } + else + { + return -1 ; + } +} + inline int SndfileHandle::error (void) const { return sf_error (p->sf) ; }