Fix bug with ssl_cache and max_entries=0
diff --git a/library/ssl_cache.c b/library/ssl_cache.c
index 6fff54b..d94a7d9 100644
--- a/library/ssl_cache.c
+++ b/library/ssl_cache.c
@@ -186,8 +186,14 @@
         /*
          * Reuse oldest entry if max_entries reached
          */
-        if( old != NULL && count >= cache->max_entries )
+        if( count >= cache->max_entries )
         {
+            if( old == NULL )
+            {
+                ret = 1;
+                goto exit;
+            }
+
             cur = old;
             memset( &cur->session, 0, sizeof(ssl_session) );
 #if defined(POLARSSL_X509_CRT_PARSE_C)
@@ -228,6 +234,9 @@
 #endif /* POLARSSL_HAVE_TIME */
         else
         {
+            /*
+             * max_entries not reached, create new entry
+             */
             cur = (ssl_cache_entry *) polarssl_malloc( sizeof(ssl_cache_entry) );
             if( cur == NULL )
             {