---- ./crypto/asn1/tasn_fre.c	2017-03-08 11:15:50.533468363 +0000
-+++ ../talos/./crypto/asn1/tasn_fre.c	2017-03-08 11:13:57.219757093 +0000
+--- ./crypto/asn1/tasn_fre.c	2017-07-12 09:55:36.738516122 +0200
++++ ../talos/./crypto/asn1/tasn_fre.c	2017-07-12 09:53:01.614452013 +0200
 @@ -62,6 +62,13 @@
  #include <openssl/asn1t.h>
  #include <openssl/objects.h>

 static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
     int combine);
 
@@ -79,6 +86,19 @@
 	asn1_item_combine_free(pval, it, 0);
 }
 
+static void smart_free(void* ptr) {
+#ifdef COMPILE_WITH_INTEL_SGX
+	if (sgx_is_within_enclave(ptr, 1)) {
+#else
+		free(ptr);
+#endif
+#ifdef COMPILE_WITH_INTEL_SGX
+	} else {
+		ocall_free(ptr);

 static void
 asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
 {
@@ -122,7 +141,7 @@
 		if (asn1_cb)
 			asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
 		if (!combine) {
