Skip to content

Commit 34c166c

Browse files
committed
do not pass NULL to cudaFreeHost
Compared to cudaFree, which allows passing 0 as C free() (noop), the documantation for cudaFreeHost states that: "Frees the memory space pointed to by hostPtr, which must have been returned by a previous call to cudaMallocHost() or cudaHostAlloc()." So ensure that this is true (although there is no evidence that there were any problems with `cudaFreeHost(0)`).
1 parent 7f772ab commit 34c166c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/gpujpeg_decoder.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ gpujpeg_decoder_decode(struct gpujpeg_decoder* decoder, uint8_t* image, size_t i
336336
coder->data_raw_allocated_size = 0;
337337

338338
// (Re)allocate raw data in host memory
339-
cudaFreeHost(coder->data_raw);
339+
if ( coder->data_raw != NULL ) {
340+
cudaFreeHost(coder->data_raw);
341+
}
340342
coder->data_raw = NULL;
341343
cudaMallocHost((void**)&coder->data_raw, coder->data_raw_size * sizeof(uint8_t));
342344
// (Re)allocate raw data in device memory

src/utils/image_delegate.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ gpujpeg_cuda_realloc_sized_host(void* ptr, int oldsz, int newsz);
9292
static void
9393
gpujpeg_cuda_free_host(void* ptr)
9494
{
95+
if ( ptr == NULL ) {
96+
return;
97+
}
9598
GPUJPEG_CHECK_EX(cudaFreeHost(ptr), "Could not free host pointer", );
9699
}
97100

0 commit comments

Comments
 (0)