Forráskód Böngészése

- malloc debugging for openssl and random malloc null returns turened off
(I've commited this yesterday by mistake)

Andrei Pelinescu-Onciul 18 éve
szülő
commit
3d980a8e30
1 módosított fájl, 18 hozzáadás és 6 törlés
  1. 18 6
      modules/tls/tls_init.c

+ 18 - 6
modules/tls/tls_init.c

@@ -102,7 +102,7 @@ int tls_force_run = 0; /* ignore some start-up sanity checks, use it
 
 
 const SSL_METHOD* ssl_methods[TLS_USE_SSLv23 + 1];
 const SSL_METHOD* ssl_methods[TLS_USE_SSLv23 + 1];
 
 
-#define TLS_MALLOC_DBG /* extra malloc debug info from openssl */
+#undef TLS_MALLOC_DBG /* extra malloc debug info from openssl */
 /*
 /*
  * Wrappers around SER shared memory functions
  * Wrappers around SER shared memory functions
  * (which can be macros)
  * (which can be macros)
@@ -110,7 +110,7 @@ const SSL_METHOD* ssl_methods[TLS_USE_SSLv23 + 1];
 #ifdef TLS_MALLOC_DBG
 #ifdef TLS_MALLOC_DBG
 #include <execinfo.h>
 #include <execinfo.h>
 
 
-#define RAND_NULL_MALLOC (1024)
+/*#define RAND_NULL_MALLOC (1024) */
 #define NULL_GRACE_PERIOD 10U
 #define NULL_GRACE_PERIOD 10U
 
 
 
 
@@ -172,14 +172,16 @@ inline static int backtrace2str(char* buf, int size)
 static void* ser_malloc(size_t size, const char* file, int line)
 static void* ser_malloc(size_t size, const char* file, int line)
 {
 {
 	void  *p;
 	void  *p;
-	static ticks_t st=0;
 	char bt_buf[1024];
 	char bt_buf[1024];
 	int s;
 	int s;
+#ifdef RAND_NULL_MALLOC
+	static ticks_t st=0;
 
 
 	/* start random null returns only after 
 	/* start random null returns only after 
 	 * NULL_GRACE_PERIOD from first call */
 	 * NULL_GRACE_PERIOD from first call */
 	if (st==0) st=get_ticks();
 	if (st==0) st=get_ticks();
 	if (((get_ticks()-st)<NULL_GRACE_PERIOD) || (random()%RAND_NULL_MALLOC)){
 	if (((get_ticks()-st)<NULL_GRACE_PERIOD) || (random()%RAND_NULL_MALLOC)){
+#endif
 		s=backtrace2str(bt_buf, sizeof(bt_buf));
 		s=backtrace2str(bt_buf, sizeof(bt_buf));
 		/* ugly hack: keep the bt inside the alloc'ed fragment */
 		/* ugly hack: keep the bt inside the alloc'ed fragment */
 		p=_shm_malloc(size+s, file, "via ser_malloc", line);
 		p=_shm_malloc(size+s, file, "via ser_malloc", line);
@@ -191,6 +193,7 @@ static void* ser_malloc(size_t size, const char* file, int line)
 			((struct qm_frag*)((char*)p-sizeof(struct qm_frag)))->func=
 			((struct qm_frag*)((char*)p-sizeof(struct qm_frag)))->func=
 				p+size;
 				p+size;
 		}
 		}
+#ifdef RAND_NULL_MALLOC
 	}else{
 	}else{
 		p=0;
 		p=0;
 		backtrace2str(bt_buf, sizeof(bt_buf));
 		backtrace2str(bt_buf, sizeof(bt_buf));
@@ -198,6 +201,7 @@ static void* ser_malloc(size_t size, const char* file, int line)
 				" returning null - bt: %s\n",
 				" returning null - bt: %s\n",
 				size, file, line, bt_buf);
 				size, file, line, bt_buf);
 	}
 	}
+#endif
 	return p;
 	return p;
 }
 }
 
 
@@ -205,14 +209,16 @@ static void* ser_malloc(size_t size, const char* file, int line)
 static void* ser_realloc(void *ptr, size_t size, const char* file, int line)
 static void* ser_realloc(void *ptr, size_t size, const char* file, int line)
 {
 {
 	void  *p;
 	void  *p;
-	static ticks_t st=0;
 	char bt_buf[1024];
 	char bt_buf[1024];
 	int s;
 	int s;
+#ifdef RAND_NULL_MALLOC
+	static ticks_t st=0;
 
 
 	/* start random null returns only after 
 	/* start random null returns only after 
 	 * NULL_GRACE_PERIOD from first call */
 	 * NULL_GRACE_PERIOD from first call */
 	if (st==0) st=get_ticks();
 	if (st==0) st=get_ticks();
 	if (((get_ticks()-st)<NULL_GRACE_PERIOD) || (random()%RAND_NULL_MALLOC)){
 	if (((get_ticks()-st)<NULL_GRACE_PERIOD) || (random()%RAND_NULL_MALLOC)){
+#endif
 		s=backtrace2str(bt_buf, sizeof(bt_buf));
 		s=backtrace2str(bt_buf, sizeof(bt_buf));
 		p=_shm_realloc(ptr, size+s, file, "via ser_realloc", line);
 		p=_shm_realloc(ptr, size+s, file, "via ser_realloc", line);
 		if (p==0){
 		if (p==0){
@@ -223,6 +229,7 @@ static void* ser_realloc(void *ptr, size_t size, const char* file, int line)
 			((struct qm_frag*)((char*)p-sizeof(struct qm_frag)))->func=
 			((struct qm_frag*)((char*)p-sizeof(struct qm_frag)))->func=
 				p+size;
 				p+size;
 		}
 		}
+#ifdef RAND_NULL_MALLOC
 	}else{
 	}else{
 		p=0;
 		p=0;
 		backtrace2str(bt_buf, sizeof(bt_buf));
 		backtrace2str(bt_buf, sizeof(bt_buf));
@@ -230,10 +237,11 @@ static void* ser_realloc(void *ptr, size_t size, const char* file, int line)
 					" returning null - bt: %s\n", ptr, size, file, line,
 					" returning null - bt: %s\n", ptr, size, file, line,
 					bt_buf);
 					bt_buf);
 	}
 	}
+#endif
 	return p;
 	return p;
 }
 }
 
 
-#else
+#else /*TLS_MALLOC_DBG */
 
 
 static void* ser_malloc(size_t size)
 static void* ser_malloc(size_t size)
 {
 {
@@ -241,7 +249,7 @@ static void* ser_malloc(size_t size)
 }
 }
 
 
 
 
-static void* ser_realloc(void *ptr, size_t size, const char* file, int line)
+static void* ser_realloc(void *ptr, size_t size)
 {
 {
 		return shm_realloc(ptr, size);
 		return shm_realloc(ptr, size);
 }
 }
@@ -491,7 +499,11 @@ int init_tls_h(void)
 	      * this has to be called before any function calling CRYPTO_malloc,
 	      * this has to be called before any function calling CRYPTO_malloc,
 	      * CRYPTO_malloc will set allow_customize in openssl to 0 
 	      * CRYPTO_malloc will set allow_customize in openssl to 0 
 	      */
 	      */
+#ifdef TLS_MALLOC_DBG
 	if (!CRYPTO_set_mem_ex_functions(ser_malloc, ser_realloc, ser_free)) {
 	if (!CRYPTO_set_mem_ex_functions(ser_malloc, ser_realloc, ser_free)) {
+#else
+	if (!CRYPTO_set_mem_functions(ser_malloc, ser_realloc, ser_free)) {
+#endif
 		ERR("Unable to set the memory allocation functions\n");
 		ERR("Unable to set the memory allocation functions\n");
 		return -1;
 		return -1;
 	}
 	}