#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-#include "cryptlib.h"
+#include "internal/cryptlib.h"
#include <openssl/crypto.h>
#include <openssl/buffer.h>
#include <openssl/bio.h>
static void app_info_free(APP_INFO *inf)
{
+ if (!inf)
+ return;
if (--(inf->references) <= 0) {
- if (inf->next != NULL) {
- app_info_free(inf->next);
- }
+ app_info_free(inf->next);
OPENSSL_free(inf);
}
}
if (is_MemCheck_on()) {
MemCheck_off(); /* obtain MALLOC2 lock */
- if ((ami = (APP_INFO *)OPENSSL_malloc(sizeof(APP_INFO))) == NULL) {
+ if ((ami = OPENSSL_malloc(sizeof(*ami))) == NULL) {
ret = 0;
goto err;
}
if (is_MemCheck_on()) {
MemCheck_off(); /* make sure we hold MALLOC2 lock */
- if ((m = (MEM *)OPENSSL_malloc(sizeof(MEM))) == NULL) {
+ if ((m = OPENSSL_malloc(sizeof(*m))) == NULL) {
OPENSSL_free(addr);
MemCheck_on(); /* release MALLOC2 lock if num_disabled drops
* to 0 */
fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5ld] - 0x%p (%d)\n",
mp->order, mp->addr, mp->num);
#endif
- if (mp->app_info != NULL)
- app_info_free(mp->app_info);
+ app_info_free(mp->app_info);
OPENSSL_free(mp);
}
typedef struct mem_leak_st {
BIO *bio;
int chunks;
+ int seen;
long bytes;
} MEM_LEAK;
#define BUF_REMAIN (sizeof buf - (size_t)(bufp - buf))
- if (m->addr == (char *)l->bio)
+ /* Is one "leak" the BIO we were given? */
+ if (m->addr == (char *)l->bio) {
+ l->seen = 1;
return;
+ }
if (options & V_CRYPTO_MDEBUG_TIME) {
lcl = localtime(&m->time);
ml.bio = b;
ml.bytes = 0;
ml.chunks = 0;
+ ml.seen = 0;
if (mh != NULL)
lh_MEM_doall_arg(mh, LHASH_DOALL_ARG_FN(print_leak), MEM_LEAK, &ml);
+ /* Don't count the BIO that was passed in as a "leak" */
+ if (ml.seen && ml.chunks >= 1 && ml.bytes >= (int)sizeof (*b)) {
+ ml.chunks--;
+ ml.bytes -= (int)sizeof (*b);
+ }
if (ml.chunks != 0) {
BIO_printf(b, "%ld bytes leaked in %d chunks\n", ml.bytes, ml.chunks);
#ifdef CRYPTO_MDEBUG_ABORT
old_mh_mode = mh_mode;
mh_mode = CRYPTO_MEM_CHECK_OFF;
- if (mh != NULL) {
- lh_MEM_free(mh);
- mh = NULL;
- }
+ lh_MEM_free(mh);
+ mh = NULL;
if (amih != NULL) {
if (lh_APP_INFO_num_items(amih) == 0) {
lh_APP_INFO_free(amih);