From 1e11b16d7375ed603a0a4cd6f95d9dca2e17e96d Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 27 Apr 2017 07:49:19 +0200 Subject: [PATCH] opencl: Fix crash on hosts with no OpenCL platform A Tesseract binary with OpenCL support can also run on a host without any OpenCL platform, as it simply uses the normal CPU based code. Signed-off-by: Stefan Weil --- opencl/openclwrapper.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/opencl/openclwrapper.cpp b/opencl/openclwrapper.cpp index c252f92bc5..523f3355b8 100644 --- a/opencl/openclwrapper.cpp +++ b/opencl/openclwrapper.cpp @@ -170,15 +170,15 @@ static ds_status initDSProfile(ds_profile** p, const char* version) { memset(profile, 0, sizeof(ds_profile)); clGetPlatformIDs(0, nullptr, &numPlatforms); - if (numPlatforms == 0) - goto cleanup; - platforms = (cl_platform_id*)malloc(numPlatforms*sizeof(cl_platform_id)); - if (platforms == nullptr) { - status = DS_MEMORY_ERROR; - goto cleanup; + if (numPlatforms > 0) { + platforms = (cl_platform_id*)malloc(numPlatforms*sizeof(cl_platform_id)); + if (platforms == nullptr) { + status = DS_MEMORY_ERROR; + goto cleanup; + } + clGetPlatformIDs(numPlatforms, platforms, nullptr); } - clGetPlatformIDs(numPlatforms, platforms, nullptr); numDevices = 0; for (i = 0; i < (unsigned int)numPlatforms; i++) {