summaryrefslogtreecommitdiffstats
path: root/cuda/2d/util.cu
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2021-11-22 14:44:50 +0100
committerWillem Jan Palenstijn <wjp@usecode.org>2021-11-26 12:09:09 +0100
commit7cad7b813838ed2ddb65a4c9ea1c08c625c50043 (patch)
tree59ca80ff9e2d4356c28ee48f64eb68494e5f3372 /cuda/2d/util.cu
parentbe2da43a560a7241c56e727fb481f1389e9f7fdf (diff)
downloadastra-7cad7b813838ed2ddb65a4c9ea1c08c625c50043.tar.gz
astra-7cad7b813838ed2ddb65a4c9ea1c08c625c50043.tar.bz2
astra-7cad7b813838ed2ddb65a4c9ea1c08c625c50043.tar.xz
astra-7cad7b813838ed2ddb65a4c9ea1c08c625c50043.zip
Fix memleak in error handling
Diffstat (limited to 'cuda/2d/util.cu')
-rw-r--r--cuda/2d/util.cu17
1 files changed, 13 insertions, 4 deletions
diff --git a/cuda/2d/util.cu b/cuda/2d/util.cu
index 2ad3c0f..4a58880 100644
--- a/cuda/2d/util.cu
+++ b/cuda/2d/util.cu
@@ -126,7 +126,7 @@ void duplicateProjectionData(float* D_dst, float* D_src, unsigned int pitch, con
cudaMemcpy2D(D_dst, sizeof(float)*pitch, D_src, sizeof(float)*pitch, sizeof(float)*dims.iProjDets, dims.iProjAngles, cudaMemcpyDeviceToDevice);
}
-bool createTextureObject2D(float* data, cudaArray*& dataArray, cudaTextureObject_t& texObj, unsigned int pitch, unsigned int width, unsigned int height)
+bool createArrayAndTextureObject2D(float* data, cudaArray*& dataArray, cudaTextureObject_t& texObj, unsigned int pitch, unsigned int width, unsigned int height)
{
// TODO: For very small sizes (roughly <=512x128) with few angles (<=180)
// not using an array is more efficient.
@@ -135,8 +135,12 @@ bool createTextureObject2D(float* data, cudaArray*& dataArray, cudaTextureObject
cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
dataArray = 0;
- cudaMallocArray(&dataArray, &channelDesc, width, height);
- cudaMemcpy2DToArray(dataArray, 0, 0, data, pitch*sizeof(float), width*sizeof(float), height, cudaMemcpyDeviceToDevice);
+ if (!checkCuda(cudaMallocArray(&dataArray, &channelDesc, width, height), "createTextureObject2D malloc"))
+ return false;
+ if (!checkCuda(cudaMemcpy2DToArray(dataArray, 0, 0, data, pitch*sizeof(float), width*sizeof(float), height, cudaMemcpyDeviceToDevice), "createTextureObject2D memcpy")) {
+ cudaFreeArray(dataArray);
+ return false;
+ }
cudaResourceDesc resDesc;
memset(&resDesc, 0, sizeof(resDesc));
@@ -153,7 +157,12 @@ bool createTextureObject2D(float* data, cudaArray*& dataArray, cudaTextureObject
texObj = 0;
- return checkCuda(cudaCreateTextureObject(&texObj, &resDesc, &texDesc, NULL), "createTextureObject2D");
+ if (!checkCuda(cudaCreateTextureObject(&texObj, &resDesc, &texDesc, NULL), "createTextureObject2D")) {
+ cudaFreeArray(dataArray);
+ return false;
+ }
+
+ return true;
}
bool createTextureObjectPitch2D(float* data, cudaTextureObject_t& texObj, unsigned int pitch, unsigned int width, unsigned int height, cudaTextureAddressMode mode)