From 297bce40545793d545747e25f614b09a185ef489 Mon Sep 17 00:00:00 2001
From: houmingyong <houmingyong@huawei.com>
Date: Wed, 23 Feb 2022 20:33:32 +0800
Subject: [PATCH] fix double free

---
 src/host_src/gp/gp_enclave.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/host_src/gp/gp_enclave.c b/src/host_src/gp/gp_enclave.c
index c7554de..9bc9514 100644
--- a/src/host_src/gp/gp_enclave.c
+++ b/src/host_src/gp/gp_enclave.c
@@ -255,10 +255,15 @@ static bool handle_ocall(uint32_t agent_id, int dev_fd, void *buffer, cc_ocall_f
     }
     ret = true;
 done:
-    free(tmp_input_buffer);
-    free(tmp_output_buffer);
-    tmp_input_buffer = NULL;
-    tmp_output_buffer = NULL;
+    if (tmp_input_buffer != NULL) {
+        free(tmp_input_buffer);
+        tmp_input_buffer = NULL;
+    }
+    if (tmp_output_buffer != NULL) {
+        free(tmp_output_buffer);
+        tmp_output_buffer = NULL;
+    }
+
     return ret;
 }
 
-- 
2.27.0

