From a2b8b2942ed0f863b3275e82b24b078d0b41638d Mon Sep 17 00:00:00 2001 From: Pascal Bauer Date: Fri, 9 Dec 2022 12:43:49 +0100 Subject: [PATCH] fixed memory leak (missing deletes before return) Signed-off-by: Pascal Bauer --- fpga/lib/ips/emc.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/fpga/lib/ips/emc.cpp b/fpga/lib/ips/emc.cpp index 62d4a3cfb..6b0ccf2fb 100644 --- a/fpga/lib/ips/emc.cpp +++ b/fpga/lib/ips/emc.cpp @@ -118,8 +118,10 @@ EMC::flash(uint32_t offset, uint32_t length, uint8_t *data) /* Reset the Flash Device. This clears the ret registers and puts * the device in Read mode. */ ret = XFlash_Reset(&xflash); - if (ret != XST_SUCCESS) + if (ret != XST_SUCCESS){ + delete[] verify_data; return false; + } /* Perform an unlock operation before the erase operation for the Intel * Flash. The erase operation will result in an error if the block is @@ -128,30 +130,39 @@ EMC::flash(uint32_t offset, uint32_t length, uint8_t *data) (xflash.CommandSet == XFL_CMDSET_INTEL_EXTENDED) || (xflash.CommandSet == XFL_CMDSET_INTEL_G18)) { ret = XFlash_Unlock(&xflash, offset, 0); - if(ret != XST_SUCCESS) + if(ret != XST_SUCCESS){ + delete[] verify_data; return false; + } } // Perform the Erase operation. ret = XFlash_Erase(&xflash, start, length); - if (ret != XST_SUCCESS) + if (ret != XST_SUCCESS){ + delete[] verify_data; return false; + } // Perform the Write operation. ret = XFlash_Write(&xflash, start, length, data); - if (ret != XST_SUCCESS) + if (ret != XST_SUCCESS){ + delete[] verify_data; return false; + } // Perform the read operation. ret = XFlash_Read(&xflash, start, length, verify_data); if(ret != XST_SUCCESS) { + delete[] verify_data; return false; } // Compare the data read against the data Written. for (unsigned i = 0; i < length; i++) { - if (verify_data[i] != data[i]) + if (verify_data[i] != data[i]){ + delete[] verify_data; return false; + } } delete[] verify_data;