diff --git a/ocl_icd_loader.c b/ocl_icd_loader.c index b981bef..c83f8bd 100644 --- a/ocl_icd_loader.c +++ b/ocl_icd_loader.c @@ -526,8 +526,13 @@ static inline void _find_and_check_platforms(cl_uint num_icds) { if (KHR_ICD2_HAS_TAG(p->pid)) { - _populate_dispatch_table(p->pid, pltfn_fn_ptr, &p->disp_data.dispatch); - spltdd_fn_ptr(p->pid, &p->disp_data); + p->disp_data = (struct _cl_disp_data *)calloc(1, sizeof(struct _cl_disp_data)); + if (!p->disp_data) { + debug(D_WARN, "Not enough memory to allocate dispatch data, skipping ICD"); + continue; + } + _populate_dispatch_table(p->pid, pltfn_fn_ptr, &p->disp_data->dispatch); + spltdd_fn_ptr(p->pid, p->disp_data); debug(D_LOG, "Found icd 2 platform, using loader managed dispatch"); } diff --git a/ocl_icd_loader.h b/ocl_icd_loader.h index 391f669..7e60995 100644 --- a/ocl_icd_loader.h +++ b/ocl_icd_loader.h @@ -119,14 +119,14 @@ struct _cl_disp_data (object)->dispatch) struct platform_icd { - char *extension_suffix; - char *version; - struct vendor_icd *vicd; - cl_platform_id pid; - cl_uint ngpus; /* number of GPU devices */ - cl_uint ncpus; /* number of CPU devices */ - cl_uint ndevs; /* total number of devices, of all types */ - struct _cl_disp_data disp_data; + char *extension_suffix; + char *version; + struct vendor_icd *vicd; + cl_platform_id pid; + cl_uint ngpus; /* number of GPU devices */ + cl_uint ncpus; /* number of CPU devices */ + cl_uint ndevs; /* total number of devices, of all types */ + struct _cl_disp_data *disp_data; }; __attribute__((visibility("hidden")))