From aa325035704f932e29217274aeab26ae46847a7b Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 17 Feb 2017 15:56:36 +0100 Subject: Fix cuda3d geometry memory leaks --- cuda/3d/astra3d.cu | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'cuda/3d/astra3d.cu') diff --git a/cuda/3d/astra3d.cu b/cuda/3d/astra3d.cu index 8e0946e..30cbe1b 100644 --- a/cuda/3d/astra3d.cu +++ b/cuda/3d/astra3d.cu @@ -319,6 +319,9 @@ AstraSIRT3d::~AstraSIRT3d() delete[] pData->projs; pData->projs = 0; + delete[] pData->parprojs; + pData->parprojs = 0; + cudaFree(pData->D_projData.ptr); pData->D_projData.ptr = 0; @@ -702,6 +705,9 @@ AstraCGLS3d::~AstraCGLS3d() delete[] pData->projs; pData->projs = 0; + delete[] pData->parprojs; + pData->parprojs = 0; + cudaFree(pData->D_projData.ptr); pData->D_projData.ptr = 0; @@ -1133,19 +1139,27 @@ bool astraCudaBP(float* pfVolume, const float* pfProjections, cudaError_t err = cudaGetLastError(); // Ignore errors caused by calling cudaSetDevice multiple times - if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) + if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) { + delete[] pParProjs; + delete[] pConeProjs; return false; + } } cudaPitchedPtr D_volumeData = allocateVolumeData(dims); ok = D_volumeData.ptr; - if (!ok) + if (!ok) { + delete[] pParProjs; + delete[] pConeProjs; return false; + } cudaPitchedPtr D_projData = allocateProjectionData(dims); ok = D_projData.ptr; if (!ok) { + delete[] pParProjs; + delete[] pConeProjs; cudaFree(D_volumeData.ptr); return false; } @@ -1156,6 +1170,8 @@ bool astraCudaBP(float* pfVolume, const float* pfProjections, ok &= zeroVolumeData(D_volumeData, dims); if (!ok) { + delete[] pParProjs; + delete[] pConeProjs; cudaFree(D_volumeData.ptr); cudaFree(D_projData.ptr); return false; @@ -1168,6 +1184,8 @@ bool astraCudaBP(float* pfVolume, const float* pfProjections, ok &= copyVolumeFromDevice(pfVolume, D_volumeData, dims, dims.iVolX); + delete[] pParProjs; + delete[] pConeProjs; cudaFree(D_volumeData.ptr); cudaFree(D_projData.ptr); @@ -1208,19 +1226,27 @@ bool astraCudaBP_SIRTWeighted(float* pfVolume, cudaError_t err = cudaGetLastError(); // Ignore errors caused by calling cudaSetDevice multiple times - if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) + if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) { + delete[] pParProjs; + delete[] pConeProjs; return false; + } } cudaPitchedPtr D_pixelWeight = allocateVolumeData(dims); ok = D_pixelWeight.ptr; - if (!ok) + if (!ok) { + delete[] pParProjs; + delete[] pConeProjs; return false; + } cudaPitchedPtr D_volumeData = allocateVolumeData(dims); ok = D_volumeData.ptr; if (!ok) { + delete[] pParProjs; + delete[] pConeProjs; cudaFree(D_pixelWeight.ptr); return false; } @@ -1228,6 +1254,8 @@ bool astraCudaBP_SIRTWeighted(float* pfVolume, cudaPitchedPtr D_projData = allocateProjectionData(dims); ok = D_projData.ptr; if (!ok) { + delete[] pParProjs; + delete[] pConeProjs; cudaFree(D_pixelWeight.ptr); cudaFree(D_volumeData.ptr); return false; @@ -1244,6 +1272,8 @@ bool astraCudaBP_SIRTWeighted(float* pfVolume, processVol3D(D_pixelWeight, dims); if (!ok) { + delete[] pParProjs; + delete[] pConeProjs; cudaFree(D_pixelWeight.ptr); cudaFree(D_volumeData.ptr); cudaFree(D_projData.ptr); -- cgit v1.2.3