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>
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);
}
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
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
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
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(),
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 */