diff options
author | Luo Xionghu <xionghu.luo@intel.com> | 2015-09-21 15:51:26 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2015-09-21 16:29:27 +0800 |
commit | ff618562bbffafd7aba1861a0126c5ecf2ade066 (patch) | |
tree | 1a6b184999be20ecb67623ff61bb382fec5828d5 | |
parent | fc30ff72401a54d019426956a58af154add106e8 (diff) |
should check the return value of cl_program_new.
catch the error: out of host memery.
Signed-off-by: Luo Xionghu <xionghu.luo@intel.com>
Reviewed-by: "Yang, Rong R" <rong.r.yang@intel.com>
-rw-r--r-- | src/cl_program.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/cl_program.c b/src/cl_program.c index 0564b6f7..82dd3e34 100644 --- a/src/cl_program.c +++ b/src/cl_program.c @@ -224,6 +224,10 @@ cl_program_create_from_binary(cl_context ctx, } program = cl_program_new(ctx); + if (UNLIKELY(program == NULL)) { + err = CL_OUT_OF_HOST_MEMORY; + goto error; + } // TODO: Need to check the binary format here to return CL_INVALID_BINARY. TRY_ALLOC(program->binary, cl_calloc(lengths[0], sizeof(char))); @@ -379,6 +383,11 @@ cl_program_create_from_llvm(cl_context ctx, INVALID_VALUE_IF (file_name == NULL); program = cl_program_new(ctx); + if (UNLIKELY(program == NULL)) { + err = CL_OUT_OF_HOST_MEMORY; + goto error; + } + program->opaque = compiler_program_new_from_llvm(ctx->device->device_id, file_name, NULL, NULL, NULL, program->build_log_max_sz, program->build_log, &program->build_log_sz, 1); if (UNLIKELY(program->opaque == NULL)) { err = CL_INVALID_PROGRAM; @@ -417,6 +426,11 @@ cl_program_create_from_source(cl_context ctx, // the real compilation step will be done at build time since we do not have // yet the compilation options program = cl_program_new(ctx); + if (UNLIKELY(program == NULL)) { + err = CL_OUT_OF_HOST_MEMORY; + goto error; + } + TRY_ALLOC (lens, cl_calloc(count, sizeof(int32_t))); for (i = 0; i < (int) count; ++i) { size_t len; @@ -633,6 +647,10 @@ cl_program_link(cl_context context, } p = cl_program_new(context); + if (UNLIKELY(p == NULL)) { + err = CL_OUT_OF_HOST_MEMORY; + goto error; + } if (!check_cl_version_option(p, options)) { err = CL_BUILD_PROGRAM_FAILURE; |