Commit 65962686 authored by Richard Levitte's avatar Richard Levitte
Browse files

In Message-ID: <003201bfb332$14a07520$0801a8c0@janm.transactionsite.com>,

"Jan Mikkelsen" <janm@transactionsite.com> correctly states that the
OpenSSL header files have #include's and extern "C"'s in an incorrect
order.  Thusly fixed.

Also, make the memory debugging routines defined and declared with
prototypes, and use void* instead of char* for memory blobs.

And last of all, redo the ugly callback construct for elegance and
better definition (with prototypes).
parent b50e1bd3
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -59,10 +59,6 @@
#ifndef HEADER_CRYPTO_H
#define HEADER_CRYPTO_H

#ifdef  __cplusplus
extern "C" {
#endif

#include <stdlib.h>

#ifndef NO_FP_API
@@ -82,6 +78,10 @@ extern "C" {
#endif


#ifdef  __cplusplus
extern "C" {
#endif

/* Backward compatibility to SSLeay */
/* This is more to be used to check the correct DLL is being used
 * in the MS world. */
@@ -303,10 +303,18 @@ int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file,
 * call the latter last if you need different functions */
int CRYPTO_set_mem_functions(void *(*m)(size_t),void *(*r)(void *,size_t), void (*f)(void *));
int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*free_func)(void *));
int CRYPTO_set_mem_debug_functions(void (*m)(),void (*r)(),void (*f)(),void (*so)(),long (*go)());
int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int),
				   void (*r)(void *,void *,int,const char *,int,int),
				   void (*f)(void *,int),
				   void (*so)(long),
				   long (*go)(void));
void CRYPTO_get_mem_functions(void *(**m)(size_t),void *(**r)(void *, size_t), void (**f)(void *));
void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *));
void CRYPTO_get_mem_debug_functions(void (**m)(),void (**r)(),void (**f)(),void (**so)(),long (**go)());
void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),
				    void (**r)(void *,void *,int,const char *,int,int),
				    void (**f)(void *,int),
				    void (**so)(long),
				    long (**go)(void));

void *CRYPTO_malloc_locked(int num, const char *file, int line);
void CRYPTO_free_locked(void *);
+29 −18
Original line number Diff line number Diff line
@@ -81,19 +81,22 @@ static void (*free_func)(void *) = free;
/* XXX use correct function pointer types */
#ifdef CRYPTO_MDEBUG
/* use default functions from mem_dbg.c */
  static void (*malloc_debug_func)()= (void (*)())CRYPTO_dbg_malloc;
  static void (*realloc_debug_func)()= (void (*)())CRYPTO_dbg_realloc;
  static void (*free_debug_func)()= (void (*)())CRYPTO_dbg_free;
  static void (*set_debug_options_func)()= (void (*)())CRYPTO_dbg_set_options;
  static long (*get_debug_options_func)()= (long (*)())CRYPTO_dbg_get_options;
static void (*malloc_debug_func)(void *,int,const char *,int,int)
	= CRYPTO_dbg_malloc;
static void (*realloc_debug_func)(void *,void *,int,const char *,int,int)
	= CRYPTO_dbg_realloc;
static void (*free_debug_func)(void *,int) = CRYPTO_dbg_free;
static void (*set_debug_options_func)(long) = CRYPTO_dbg_set_options;
static long (*get_debug_options_func)(void) = CRYPTO_dbg_get_options;
#else
/* applications can use CRYPTO_malloc_debug_init() to select above case
 * at run-time */
  static void (*malloc_debug_func)()= NULL;
  static void (*realloc_debug_func)()= NULL;
  static void (*free_debug_func)()= NULL;
  static void (*set_debug_options_func)()= NULL;
  static long (*get_debug_options_func)()= NULL;
static void (*malloc_debug_func)(void *,int,const char *,int,int) = NULL;
static void (*realloc_debug_func)(void *,void *,int,const char *,int,int)
	= NULL;
static void (*free_debug_func)(void *,int) = NULL;
static void (*set_debug_options_func)(long) = NULL;
static long (*get_debug_options_func)(void) = NULL;
#endif


@@ -123,7 +126,11 @@ int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*f)(void *))
	return 1;
	}

int CRYPTO_set_mem_debug_functions(void (*m)(), void (*r)(), void (*f)(),void (*so)(),long (*go)())
int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int),
				   void (*r)(void *,void *,int,const char *,int,int),
				   void (*f)(void *,int),
				   void (*so)(long),
				   long (*go)(void))
	{
	if (!allow_customize_debug)
		return 0;
@@ -149,7 +156,11 @@ void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *))
	if (f != NULL) *f=free_locked_func;
	}

void CRYPTO_get_mem_debug_functions(void (**m)(), void (**r)(), void (**f)(),void (**so)(),long (**go)())
void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),
				    void (**r)(void *,void *,int,const char *,int,int),
				    void (**f)(void *,int),
				    void (**so)(long),
				    long (**go)(void))
	{
	if (m != NULL) *m=malloc_debug_func;
	if (r != NULL) *r=realloc_debug_func;
@@ -161,7 +172,7 @@ void CRYPTO_get_mem_debug_functions(void (**m)(), void (**r)(), void (**f)(),voi

void *CRYPTO_malloc_locked(int num, const char *file, int line)
	{
	char *ret = NULL;
	void *ret = NULL;

	allow_customize = 0;
	if (malloc_debug_func != NULL)
@@ -193,7 +204,7 @@ void CRYPTO_free_locked(void *str)

void *CRYPTO_malloc(int num, const char *file, int line)
	{
	char *ret = NULL;
	void *ret = NULL;

	allow_customize = 0;
	if (malloc_debug_func != NULL)
@@ -213,7 +224,7 @@ void *CRYPTO_malloc(int num, const char *file, int line)

void *CRYPTO_realloc(void *str, int num, const char *file, int line)
	{
	char *ret = NULL;
	void *ret = NULL;

	if (realloc_debug_func != NULL)
		realloc_debug_func(str, NULL, num, file, line, 0);
+20 −28
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's
typedef struct mem_st
/* memory-block description */
	{
	char *addr;
	void *addr;
	int num;
	const char *file;
	int line;
@@ -221,7 +221,7 @@ long CRYPTO_dbg_get_options(void)

static int mem_cmp(MEM *a, MEM *b)
	{
	return(a->addr - b->addr);
	return((char *)a->addr - (char *)b->addr);
	}

static unsigned long mem_hash(MEM *a)
@@ -696,32 +696,6 @@ void CRYPTO_mem_leaks(BIO *b)
#endif
	}

union void_fn_to_char_u
	{
	char *char_p;
	void (*fn_p)();
	};

static void cb_leak(MEM *m, char *cb)
	{
	union void_fn_to_char_u mem_callback;

	mem_callback.char_p=cb;
	mem_callback.fn_p(m->order,m->file,m->line,m->num,m->addr);
	}

void CRYPTO_mem_leaks_cb(void (*cb)())
	{
	union void_fn_to_char_u mem_cb;

	if (mh == NULL) return;
	CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
	mem_cb.fn_p=cb;
	lh_doall_arg(mh,(void (*)())cb_leak,mem_cb.char_p);
	mem_cb.char_p=NULL;
	CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
	}

#ifndef NO_FP_API
void CRYPTO_mem_leaks_fp(FILE *fp)
	{
@@ -736,3 +710,21 @@ void CRYPTO_mem_leaks_fp(FILE *fp)
	}
#endif



/* FIXME: We really don't allow much to the callback.  For example, it has
   no chance of reaching the info stack for the item it processes.  Should
   it really be this way?  -- Richard Levitte */
static void cb_leak(MEM *m,
		    void (**cb)(unsigned long, const char *, int, int, void *))
	{
	(**cb)(m->order,m->file,m->line,m->num,m->addr);
	}

void CRYPTO_mem_leaks_cb(void (*cb)(unsigned long, const char *, int, int, void *))
	{
	if (mh == NULL) return;
	CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
	lh_doall_arg(mh,(void (*)())cb_leak,(void *)&cb);
	CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
	}