From 1ac9286b5a64253e0200f1270afdc59b4f35f7da Mon Sep 17 00:00:00 2001 From: Rahul Manocha Date: Thu, 21 Nov 2024 17:13:25 -0800 Subject: [PATCH] SWDEV-497288 - Fix Segfault when kernel param is nullptr 1) for case where kernelParam_.func = nullptr, the validation fails in setParam call and memory is not alloced for kernelParams 2) destructor path segfaults trying to free the kernelParams memory. 3) copy of params is done after function validation is successful. Change-Id: I6338e0c89f259632e4115f0508e2f240bc207fd9 --- hipamd/src/hip_graph_internal.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hipamd/src/hip_graph_internal.hpp b/hipamd/src/hip_graph_internal.hpp index 2de2be5ea0..fac8b61e81 100644 --- a/hipamd/src/hip_graph_internal.hpp +++ b/hipamd/src/hip_graph_internal.hpp @@ -1129,6 +1129,9 @@ class GraphKernelNode : public GraphNode { const amd::KernelSignature& signature = kernel->signature(); numParams_ = signature.numParameters(); + // Copy gridDim, blockDim, sharedMemBytes and func + kernelParams_ = *pNodeParams; + // Allocate/assign memory if params are passed part of 'kernelParams' if (pNodeParams->kernelParams != nullptr) { kernelParams_.kernelParams = (void**)malloc(numParams_ * sizeof(void*)); @@ -1303,7 +1306,6 @@ class GraphKernelNode : public GraphNode { return status; } freeParams(); - kernelParams_ = *params; status = copyParams(params); if (status != hipSuccess) { ClPrint(amd::LOG_ERROR, amd::LOG_CODE, "[hipGraph] Failed to set params");