Explorar el Código

Remove pointer debugging machinery

There are tools and debugging options that can be used instead. Do not
reinvent the wheel with our own pointer tracking/debugging code.
Bradley T. Hughes hace 6 años
padre
commit
7663167dff

+ 0 - 129
src/apps/common/ns_turn_utils.c

@@ -663,135 +663,6 @@ int get_canonic_origin(const char* o, char *co, int sz)
 
 //////////////////////////////////////////////////////////////////
 
-#ifdef __cplusplus
-#if defined(TURN_MEMORY_DEBUG)
-
-#include <map>
-#include <set>
-#include <string>
-
-static volatile int tmm_init = 0;
-static pthread_mutex_t tm;
-
-typedef void* ptrtype;
-typedef std::set<ptrtype> ptrs_t;
-typedef std::map<std::string,ptrs_t> str_to_ptrs_t;
-typedef std::map<ptrtype,std::string> ptr_to_str_t;
-
-static str_to_ptrs_t str_to_ptrs;
-static ptr_to_str_t ptr_to_str;
-
-static void tm_init(void) {
-  if(!tmm_init) {
-    pthread_mutex_init(&tm,NULL);
-    tmm_init = 1;
-  }
-}
-
-static void add_tm_ptr(void *ptr, const char *id) {
-
-  UNUSED_ARG(ptr);
-  UNUSED_ARG(id);
-
-  if(!ptr)
-    return;
-
-  std::string sid(id);
-
-  str_to_ptrs_t::iterator iter;
-
-  pthread_mutex_lock(&tm);
-
-  iter = str_to_ptrs.find(sid);
-
-  if(iter == str_to_ptrs.end()) {
-    std::set<ptrtype> sp;
-    sp.insert(ptr);
-    str_to_ptrs[sid]=sp;
-  } else {
-	iter->second.insert(ptr);
-  }
-
-  ptr_to_str[ptr]=sid;
-
-  pthread_mutex_unlock(&tm);
-}
-
-static void del_tm_ptr(void *ptr, const char *id) {
-
-  UNUSED_ARG(ptr);
-  UNUSED_ARG(id);
-
-  if(!ptr)
-    return;
-
-  pthread_mutex_lock(&tm);
-
-  ptr_to_str_t::iterator pts_iter = ptr_to_str.find(ptr);
-  if(pts_iter == ptr_to_str.end()) {
-
-	  printf("Tring to free unknown pointer (1): %s\n",id);
-
-  } else {
-
-    std::string sid = pts_iter->second;
-    ptr_to_str.erase(pts_iter);
-
-    str_to_ptrs_t::iterator iter = str_to_ptrs.find(sid);
-
-    if(iter == str_to_ptrs.end()) {
-
-    	printf("Tring to free unknown pointer (2): %s\n",id);
-
-    } else {
-
-      iter->second.erase(ptr);
-
-    }
-  }
-
-  pthread_mutex_unlock(&tm);
-}
-
-static void tm_id(char *id, const char* function, int line) {
-  sprintf(id,"%s:%d",function,line);
-}
-
-#define TM_START() char id[128];tm_id(id,function,line);tm_init()
-
-extern "C" void* debug_ptr_add_func(void *ptr, const char* function, int line) {
-
-	TM_START();
-
-	add_tm_ptr(ptr,id);
-
-	return ptr;
-}
-
-extern "C" void debug_ptr_del_func(void *ptr, const char* function, int line) {
-
-	TM_START();
-
-	del_tm_ptr(ptr,id);
-}
-
-extern "C" void tm_print_func(void);
-void tm_print_func(void) {
-  pthread_mutex_lock(&tm);
-  printf("=============================================\n");
-  for(str_to_ptrs_t::const_iterator iter=str_to_ptrs.begin();iter != str_to_ptrs.end();++iter) {
-	  if(iter->second.size())
-		  printf("%s: %s: %d\n",__FUNCTION__,iter->first.c_str(),(int)(iter->second.size()));
-  }
-  printf("=============================================\n");
-  pthread_mutex_unlock(&tm);
-} 
-
-#endif
-#endif
-
-////////////////////////////////
-
 int is_secure_string(const u08bits *string, int sanitizesql)
 {
 	int ret = 0;

+ 0 - 3
src/apps/relay/netengine.c

@@ -1599,9 +1599,6 @@ void run_listener_server(struct listener_server *ls)
 		run_events(ls->event_base, ls->ioa_eng);
 
 		rollover_logfile();
-
-		tm_print();
-
 	}
 }
 

+ 0 - 8
src/apps/relay/ns_ioalib_engine_impl.c

@@ -1245,7 +1245,6 @@ ioa_socket_handle ioa_create_connecting_tcp_relay_socket(ioa_socket_handle s, io
 	ret->conn_bev = bufferevent_socket_new(ret->e->event_base,
 					ret->fd,
 					TURN_BUFFEREVENTS_OPTIONS);
-	debug_ptr_add(ret->conn_bev);
 	bufferevent_setcb(ret->conn_bev, NULL, NULL, connect_eventcb, ret);
 
 	ret->conn_arg = arg;
@@ -2270,7 +2269,6 @@ static int socket_input_worker(ioa_socket_handle s)
 								s->ssl,
 								BUFFEREVENT_SSL_ACCEPTING,
 								TURN_BUFFEREVENTS_OPTIONS);
-				debug_ptr_add(s->bev);
 				bufferevent_setcb(s->bev, socket_input_handler_bev, socket_output_handler_bev,
 								eventcb_bev, s);
 				bufferevent_setwatermark(s->bev, EV_READ|EV_WRITE, 0, BUFFEREVENT_HIGH_WATERMARK);
@@ -2286,7 +2284,6 @@ static int socket_input_worker(ioa_socket_handle s)
 			s->bev = bufferevent_socket_new(s->e->event_base,
 						s->fd,
 						TURN_BUFFEREVENTS_OPTIONS);
-			debug_ptr_add(s->bev);
 			bufferevent_setcb(s->bev, socket_input_handler_bev, socket_output_handler_bev,
 				eventcb_bev, s);
 			bufferevent_setwatermark(s->bev, EV_READ|EV_WRITE, 0, BUFFEREVENT_HIGH_WATERMARK);
@@ -2338,7 +2335,6 @@ static int socket_input_worker(ioa_socket_handle s)
 								s->ssl,
 								BUFFEREVENT_SSL_ACCEPTING,
 								TURN_BUFFEREVENTS_OPTIONS);
-				debug_ptr_add(s->bev);
 				bufferevent_setcb(s->bev, socket_input_handler_bev, socket_output_handler_bev,
 								eventcb_bev, s);
 				bufferevent_setwatermark(s->bev, EV_READ|EV_WRITE, 0, BUFFEREVENT_HIGH_WATERMARK);
@@ -2354,7 +2350,6 @@ static int socket_input_worker(ioa_socket_handle s)
 			s->bev = bufferevent_socket_new(s->e->event_base,
 						s->fd,
 						TURN_BUFFEREVENTS_OPTIONS);
-			debug_ptr_add(s->bev);
 			bufferevent_setcb(s->bev, socket_input_handler_bev, socket_output_handler_bev,
 				eventcb_bev, s);
 			bufferevent_setwatermark(s->bev, EV_READ|EV_WRITE, 0, BUFFEREVENT_HIGH_WATERMARK);
@@ -3298,7 +3293,6 @@ int register_callback_on_ioa_socket(ioa_engine_handle e, ioa_socket_handle s, in
 						s->bev = bufferevent_socket_new(s->e->event_base,
 									s->fd,
 									TURN_BUFFEREVENTS_OPTIONS);
-						debug_ptr_add(s->bev);
 						bufferevent_setcb(s->bev, socket_input_handler_bev, socket_output_handler_bev,
 										eventcb_bev, s);
 						bufferevent_setwatermark(s->bev, EV_READ|EV_WRITE, 0, BUFFEREVENT_HIGH_WATERMARK);
@@ -3323,14 +3317,12 @@ int register_callback_on_ioa_socket(ioa_engine_handle e, ioa_socket_handle s, in
 											s->ssl,
 											BUFFEREVENT_SSL_ACCEPTING,
 											TURN_BUFFEREVENTS_OPTIONS);
-							debug_ptr_add(s->bev);
 						} else {
 							s->bev = bufferevent_openssl_socket_new(s->e->event_base,
 											s->fd,
 											s->ssl,
 											BUFFEREVENT_SSL_OPEN,
 											TURN_BUFFEREVENTS_OPTIONS);
-							debug_ptr_add(s->bev);
 						}
 						bufferevent_setcb(s->bev, socket_input_handler_bev, socket_output_handler_bev,
 							eventcb_bev, s);

+ 0 - 1
src/apps/relay/turn_admin_server.c

@@ -1169,7 +1169,6 @@ static void cliserver_input_handler(struct evconnlistener *l, evutil_socket_t fd
 	clisession->bev = bufferevent_socket_new(adminserver.event_base,
 					fd,
 					TURN_BUFFEREVENTS_OPTIONS);
-	debug_ptr_add(clisession->bev);
 	bufferevent_setcb(clisession->bev, cli_socket_input_handler_bev, NULL,
 			cli_eventcb_bev, clisession);
 	bufferevent_setwatermark(clisession->bev, EV_READ|EV_WRITE, 0, BUFFEREVENT_HIGH_WATERMARK);

+ 1 - 25
src/ns_turn_defs.h

@@ -105,31 +105,7 @@ static inline u64bits _ioa_ntoh64(u64bits v)
 #define ioa_ntoh64 _ioa_ntoh64
 #define ioa_hton64 _ioa_ntoh64
 
-#if defined(TURN_MEMORY_DEBUG)
-
-#if defined(TURN_LOG_FUNC)
-#undef TURN_LOG_FUNC
-#endif
-
-#define TURN_LOG_FUNC(level, ...) printf (__VA_ARGS__)
-
-  void tm_print_func(void);
-  void* debug_ptr_add_func(void *ptr, const char* function, int line);
-  void debug_ptr_del_func(void *ptr, const char* function, int line);
-
-#define debug_ptr_add(ptr) debug_ptr_add_func((ptr),__FUNCTION__,__LINE__)
-#define debug_ptr_del(ptr) debug_ptr_del_func((ptr),__FUNCTION__,__LINE__)
-#define tm_print() tm_print_func()
-
-#else
-
-#define debug_ptr_add(ptr)
-#define debug_ptr_del(ptr)
-#define tm_print() 
-
-#endif
-
-#define BUFFEREVENT_FREE(be) do { if(be) { debug_ptr_del(be); bufferevent_flush(be,EV_READ|EV_WRITE,BEV_FLUSH); bufferevent_disable(be,EV_READ|EV_WRITE); bufferevent_free(be); be = NULL;} } while(0)
+#define BUFFEREVENT_FREE(be) do { if(be) { bufferevent_flush(be,EV_READ|EV_WRITE,BEV_FLUSH); bufferevent_disable(be,EV_READ|EV_WRITE); bufferevent_free(be); be = NULL;} } while(0)
 
 #define turn_time() ((turn_time_t)time(NULL))