Make use of CRT acquire/release in mbedtls_debug_print_crt()
diff --git a/library/debug.c b/library/debug.c
index c6788b6..41769ec 100644
--- a/library/debug.c
+++ b/library/debug.c
@@ -382,6 +382,8 @@
 
     while( crt != NULL )
     {
+        int ret;
+        mbedtls_pk_context *pk;
         char buf[1024];
 
         mbedtls_snprintf( str, sizeof( str ), "%s #%d:\n", text, ++i );
@@ -390,7 +392,17 @@
         mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt );
         debug_print_line_by_line( ssl, level, file, line, buf );
 
-        debug_print_pk( ssl, level, file, line, "crt->", &crt->pk );
+        ret = mbedtls_x509_crt_pk_acquire( crt, &pk );
+        if( ret != 0 )
+        {
+            mbedtls_snprintf( str, sizeof( str ),
+                        "mbedtls_x509_crt_pk_acquire() failed with -%#04x\n",
+                        -ret );
+            debug_send_line( ssl, level, file, line, str );
+            return;
+        }
+        debug_print_pk( ssl, level, file, line, "crt->", pk );
+        mbedtls_x509_crt_pk_release( crt, pk );
 
         crt = crt->next;
     }