diff --git a/src/c_api/c_api_executor.cc b/src/c_api/c_api_executor.cc index 1f936b164326..5df0da85d1c0 100644 --- a/src/c_api/c_api_executor.cc +++ b/src/c_api/c_api_executor.cc @@ -580,6 +580,7 @@ int MXExecutorReshape(int partial_shaping, std::vector arg_grad_vec; std::vector aux_state_vec; + *out = nullptr; Executor* exec = static_cast(shared_exec); *out = exec->Reshape(partial_shaping, allow_up_sizing, ctx, ctx_map, kwargs, &in_arg_vec, &arg_grad_vec, &aux_state_vec); @@ -623,7 +624,7 @@ int MXExecutorReshape(int partial_shaping, *aux_states = &(ret->ret_handles[nd_idx]); nd_idx = ret->ret_handles.size(); } - API_END_HANDLE_ERROR(delete out); + API_END_HANDLE_ERROR(if (*out != nullptr) delete *out); } int MXExecutorGetOptimizedSymbol(ExecutorHandle handle,