From 8e9948e5d9c37741b566d4282951526ab90ac07a Mon Sep 17 00:00:00 2001 From: Christian Beer Date: Tue, 10 Nov 2015 16:29:02 +0100 Subject: [PATCH] VboxWrapper: prevent resource leak in FloppyIO::send() fixes CID 34511 found by Coverity --- samples/vboxwrapper/floppyio.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/samples/vboxwrapper/floppyio.cpp b/samples/vboxwrapper/floppyio.cpp index 129222efae..5fbba30a3d 100644 --- a/samples/vboxwrapper/floppyio.cpp +++ b/samples/vboxwrapper/floppyio.cpp @@ -197,7 +197,10 @@ int FloppyIO::send(string strData) { memset(dataToSend, 0, this->szOutput); // Check for ready state - if (!this->ready()) return this->setError(-4, "Stream is not ready!"); + if (!this->ready()) { + delete[] dataToSend; + return this->setError(-4, "Stream is not ready!"); + } // Initialize variables int szData = (int)strData.length(); @@ -214,14 +217,20 @@ int FloppyIO::send(string strData) { } // Check for stream status - if (!this->fIO->good()) return this->setError(-1, "I/O Stream reported no-good state while sending!"); + if (!this->fIO->good()) { + delete[] dataToSend; + return this->setError(-1, "I/O Stream reported no-good state while sending!"); + } // Write the data to file this->fIO->seekp(this->ofsOutput); this->fIO->write(dataToSend, this->szOutput); // Check if something went wrong after writing - if (!this->fIO->good()) return this->setError(-1, "I/O Stream reported no-good state while sending!"); + if (!this->fIO->good()) { + delete[] dataToSend; + return this->setError(-1, "I/O Stream reported no-good state while sending!"); + } // Notify the client that we placed data (Client should clear this on read) this->fIO->seekp(this->ofsCtrlByteOut); @@ -232,9 +241,14 @@ int FloppyIO::send(string strData) { if (this->synchronized) { // Wait for input control byte to become 1 int iState = this->waitForSync(this->ofsCtrlByteOut, 0, this->syncTimeout); - if (iState<0) return iState; + if (iState<0) { + delete[] dataToSend; + return iState; + } } + delete[] dataToSend; + // Return number of bytes sent return bytesSent;