Fix segfault in tests if the driver is not loaded

If the FF-A TEE driver is not loaded the setup phase of the tests will
fail as expected but then the teardown function tries to free
unallocated resources causing a segfault. This patch fixes teardown
functions by first checking if the resources were allocated before
freeing them up.

Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: Icacfdf7d8d3808503cb45a4a9233b7b2479f9aa2
diff --git a/components/app/ts-demo/test/ts-demo_tests.cpp b/components/app/ts-demo/test/ts-demo_tests.cpp
index 2cc8973..92f7369 100644
--- a/components/app/ts-demo/test/ts-demo_tests.cpp
+++ b/components/app/ts-demo/test/ts-demo_tests.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -39,11 +39,15 @@
         delete m_crypto_client;
         m_crypto_client = NULL;
 
-        service_context_close(m_crypto_service_context, m_rpc_session_handle);
-        m_rpc_session_handle = NULL;
+	if (m_crypto_service_context) {
+	        if (m_rpc_session_handle) {
+                        service_context_close(m_crypto_service_context, m_rpc_session_handle);
+                        m_rpc_session_handle = NULL;
+	        }
 
-        service_context_relinquish(m_crypto_service_context);
-        m_crypto_service_context = NULL;
+                service_context_relinquish(m_crypto_service_context);
+                m_crypto_service_context = NULL;
+	}
     }
 
     rpc_session_handle m_rpc_session_handle;