From ee2f6fcf88912b50e8d52eba92871c417f80ff88 Mon Sep 17 00:00:00 2001 From: foreman Date: Thu, 24 Oct 2019 16:29:54 -0400 Subject: [PATCH] P4 to Git Change 2019005 by gandryey@gera-win10 on 2019/10/24 16:25:40 SWDEV-79445 - OCL generic changes and code clean-up - Fix memory leaks in COMGR path. Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.cpp#64 edit --- rocclr/runtime/device/devprogram.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/rocclr/runtime/device/devprogram.cpp b/rocclr/runtime/device/devprogram.cpp index 6fffda2bf1..705b5ad31f 100644 --- a/rocclr/runtime/device/devprogram.cpp +++ b/rocclr/runtime/device/devprogram.cpp @@ -206,7 +206,7 @@ void Program::extractBuildLog(amd_comgr_data_set_t dataSet) { size_t logSize; status = extractByteCodeBinary(dataSet, AMD_COMGR_DATA_KIND_LOG, "", &logData, &logSize); buildLog_ += logData; - free(logData); + delete[] logData; } if (status != AMD_COMGR_STATUS_SUCCESS) { buildLog_ += "Warning: extracting build log failed.\n"; @@ -236,7 +236,7 @@ amd_comgr_status_t Program::extractByteCodeBinary(const amd_comgr_data_set_t inD size_t bufSize = (dataKind == AMD_COMGR_DATA_KIND_LOG) ? binarySize + 1 : binarySize; - char* binary = static_cast(malloc(bufSize)); + char* binary = new char[bufSize]; if (binary == nullptr) { amd::Comgr::release_data(binaryData); return AMD_COMGR_STATUS_ERROR; @@ -253,7 +253,7 @@ amd_comgr_status_t Program::extractByteCodeBinary(const amd_comgr_data_set_t inD amd::Comgr::release_data(binaryData); if (status != AMD_COMGR_STATUS_SUCCESS) { - free(binary); + delete[] binary; return status; } @@ -274,7 +274,7 @@ amd_comgr_status_t Program::extractByteCodeBinary(const amd_comgr_data_set_t inD *outSize = binarySize; } else { - free(binary); + delete[] binary; } return AMD_COMGR_STATUS_SUCCESS; } @@ -742,6 +742,9 @@ bool Program::compileImplLC(const std::string& sourceCode, bool ret = compileToLLVMBitcode(inputs, driverOptions, options, &binaryData, &binarySize); if (ret) { llvmBinary_.assign(binaryData, binarySize); + // Destroy the original LLVM binary, received after compilation + delete[] binaryData; + elfSectionType_ = amd::OclElf::LLVMIR; if (clBinary()->saveSOURCE()) { @@ -1165,6 +1168,10 @@ bool Program::linkImplLC(const std::vector& inputPrograms, } llvmBinary_.assign(binaryData, binarySize); + + // Destroy llvm binary, received after compilation + delete[] binaryData; + elfSectionType_ = amd::OclElf::LLVMIR; if (clBinary()->saveLLVMIR()) { @@ -1566,7 +1573,11 @@ bool Program::linkImplLC(amd::option::Options* options) { } // Save the binary and type - clBinary()->saveBIFBinary(reinterpret_cast(executable), executableSize); + clBinary()->saveBIFBinary(executable, executableSize); + + // Destroy original memory with executable after compilation + delete[] executable; + setType(TYPE_EXECUTABLE); return true;