From 0088c6cb6ee80daf3d440bf75831496af424e53f Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Fri, 16 Aug 2019 17:02:38 -0500 Subject: [PATCH] st/oxr: Fix possible null dereference. Found by clang-tidy. --- src/xrt/state_trackers/oxr/oxr_session.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/xrt/state_trackers/oxr/oxr_session.c b/src/xrt/state_trackers/oxr/oxr_session.c index 8b7757c8e..6d51a0a8f 100644 --- a/src/xrt/state_trackers/oxr/oxr_session.c +++ b/src/xrt/state_trackers/oxr/oxr_session.c @@ -607,17 +607,19 @@ oxr_session_create(struct oxr_logger *log, const XrSessionCreateInfo *createInfo, struct oxr_session **out_session) { - struct oxr_session *sess; + struct oxr_session *sess = NULL; /* Try allocating and populating. */ XrResult ret = oxr_session_create_impl(log, sys, createInfo, &sess); if (ret != XR_SUCCESS) { - /* clean up allocation first */ - XrResult cleanup_result = - oxr_handle_destroy(log, &sess->handle); - assert(cleanup_result == XR_SUCCESS); - (void)cleanup_result; + if (sess != NULL) { + /* clean up allocation first */ + XrResult cleanup_result = + oxr_handle_destroy(log, &sess->handle); + assert(cleanup_result == XR_SUCCESS); + (void)cleanup_result; + } return ret; }