From 7c75ac0c60d623c8bbdc1b6d924e4ff85547b9ca Mon Sep 17 00:00:00 2001 From: Hansang Bae Date: Thu, 30 May 2019 16:32:20 +0000 Subject: [PATCH] Add checks before pointer dereferencing This change adds checks before dereferencing a pointer returned from a function. Differential Revision: https://reviews.llvm.org/D62224 llvm-svn: 362111 --- openmp/runtime/src/ompt-specific.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openmp/runtime/src/ompt-specific.cpp b/openmp/runtime/src/ompt-specific.cpp index 99c4b6118cbd..63153d274efb 100644 --- a/openmp/runtime/src/ompt-specific.cpp +++ b/openmp/runtime/src/ompt-specific.cpp @@ -210,7 +210,8 @@ ompt_data_t *__ompt_get_thread_data_internal() { void __ompt_thread_assign_wait_id(void *variable) { kmp_info_t *ti = ompt_get_thread(); - ti->th.ompt_thread_info.wait_id = (ompt_wait_id_t)(uintptr_t)variable; + if (ti) + ti->th.ompt_thread_info.wait_id = (ompt_wait_id_t)(uintptr_t)variable; } int __ompt_get_state_internal(ompt_wait_id_t *omp_wait_id) { @@ -432,6 +433,9 @@ int __ompt_get_task_memory_internal(void **addr, size_t *size, int blocknum) { return 0; // support only a single block kmp_info_t *thr = ompt_get_thread(); + if (!thr) + return 0; + kmp_taskdata_t *taskdata = thr->th.th_current_task; kmp_task_t *task = KMP_TASKDATA_TO_TASK(taskdata);