Add memory leak return value.

Make CRYPTO_mem_leaks() and CRYPTO_mem_leaks_fp() return a status value.
Update documentation. Don't abort() if there are leaks.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c
index 1e9dd83..6e93c80 100644
--- a/crypto/mem_dbg.c
+++ b/crypto/mem_dbg.c
@@ -643,12 +643,12 @@
 
 static IMPLEMENT_LHASH_DOALL_ARG_FN(print_leak, const MEM, MEM_LEAK)
 
-void CRYPTO_mem_leaks(BIO *b)
+int CRYPTO_mem_leaks(BIO *b)
 {
     MEM_LEAK ml;
 
     if (mh == NULL && amih == NULL)
-        return;
+        return 1;
 
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
 
@@ -665,7 +665,6 @@
     }
     if (ml.chunks != 0) {
         BIO_printf(b, "%ld bytes leaked in %d chunks\n", ml.bytes, ml.chunks);
-        abort();
     } else {
         /*
          * Make sure that, if we found no leaks, memory-leak debugging itself
@@ -697,15 +696,17 @@
         CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
     }
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
+    return ml.chunks == 0 ? 1 : 0;
 }
 
 # ifndef OPENSSL_NO_STDIO
-void CRYPTO_mem_leaks_fp(FILE *fp)
+int CRYPTO_mem_leaks_fp(FILE *fp)
 {
     BIO *b;
+    int ret;
 
     if (mh == NULL)
-        return;
+        return 0;
     /*
      * Need to turn off memory checking when allocated BIOs ... especially as
      * we're creating them at a time when we're trying to check we've not
@@ -715,10 +716,11 @@
     b = BIO_new(BIO_s_file());
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
     if (b == NULL)
-        return;
+        return -1;
     BIO_set_fp(b, fp, BIO_NOCLOSE);
-    CRYPTO_mem_leaks(b);
+    ret = CRYPTO_mem_leaks(b);
     BIO_free(b);
+    return ret;
 }
 # endif
 
diff --git a/doc/crypto/OPENSSL_malloc.pod b/doc/crypto/OPENSSL_malloc.pod
index eef8c64..9dfeb39 100644
--- a/doc/crypto/OPENSSL_malloc.pod
+++ b/doc/crypto/OPENSSL_malloc.pod
@@ -132,17 +132,18 @@
 
 At the end of the program, calling CRYPTO_mem_leaks() or
 CRYPTO_mem_leaks_fp() will report all "leaked" memory, writing it
-to the specified BIO B<b> or FILE B<fp>.
-It will then L<abort(3)> if there were any unfree'd allocations.
+to the specified BIO B<b> or FILE B<fp>. These functions return 1 if
+there are no leaks, 0 if there are leaks and -1 if an error occurred.
 
 =head1 RETURN VALUES
 
 OPENSSL_malloc_init(), OPENSSL_free(), OPENSSL_clear_free()
-CRYPTO_free(), CRYPTO_clear_free(),
-CRYPTO_get_mem_functions(), and
-CRYPTO_mem_leaks()
+CRYPTO_free(), CRYPTO_clear_free() and CRYPTO_get_mem_functions()
 return no value.
 
+CRYPTO_mem_leaks() and CRYPTO_mem_leaks_fp() return 1 if there
+are no leaks, 0 if there are leaks and -1 if an error occurred.
+
 OPENSSL_malloc(), OPENSSL_zalloc(), OPENSSL_realloc(),
 OPENSSL_clear_realloc(),
 CRYPTO_malloc(), CRYPTO_zalloc(), CRYPTO_realloc(),
diff --git a/include/openssl/crypto.h b/include/openssl/crypto.h
index 5de0f50..7a45699 100644
--- a/include/openssl/crypto.h
+++ b/include/openssl/crypto.h
@@ -509,9 +509,9 @@
 void CRYPTO_mem_debug_free(void *addr, int flag);
 
 #  ifndef OPENSSL_NO_STDIO
-void CRYPTO_mem_leaks_fp(FILE *);
+int CRYPTO_mem_leaks_fp(FILE *);
 #  endif
-void CRYPTO_mem_leaks(struct bio_st *bio);
+int CRYPTO_mem_leaks(struct bio_st *bio);
 # endif
 
 /* die if we have to */