[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Libevent memory leak?



Nick, 

Are the github repo's out of sync? I can't seem to find the most recent
branch, libevent/master libevent/patches-2.0, nmathewson/* all seem to
be out of sync.

In any case, patch for the global locks issue attached.


On Mon, Jul 11, 2011 at 08:10:02PM +0200, Andrei Chirila wrote:
> Hi Mark,
> 
> Thank you for your interest in this issue.
> 
> Best regards,
> Andrei
> 
> On Mon, Jul 11, 2011 at 7:33 PM, Mark Ellzey <mthomas@xxxxxxxxxx> wrote:
> 
> > Yeah I see it now - not a huge issue but I will submit a patch here
> > soon.
> >
> > ***********************************************************************
> > To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
> > unsubscribe libevent-users    in the body.
> >
> 
> 
> 
> -- 
> Mobile: +49 151 42647382
> e-Mail: andreich@xxxxxxxxx
diff --git event.c event.c
index 4cc97e4..abd1f12 100644
--- event.c
+++ event.c
@@ -2835,4 +2835,15 @@ event_global_setup_locks_(const int enable_locks)
 		return -1;
 	return 0;
 }
+
+void
+event_global_free_locks_(void) {
+#ifndef _EVENT_DISABLE_DEBUG_MODE
+	if (_event_debug_map_lock != NULL) {
+		EVTHREAD_FREE_LOCK(_event_debug_map_lock, 0);
+	}
+#endif
+	evsig_global_free_locks_();
+	evutil_secure_rng_global_free_locks_();
+}
 #endif
diff --git evthread-internal.h evthread-internal.h
index 793b5ea..1e1ea32 100644
--- evthread-internal.h
+++ evthread-internal.h
@@ -365,6 +365,10 @@ int event_global_setup_locks_(const int enable_locks);
 int evsig_global_setup_locks_(const int enable_locks);
 int evutil_secure_rng_global_setup_locks_(const int enable_locks);
 
+void event_global_free_locks_(void);
+void evsig_global_free_locks_(void);
+void evutil_secure_rng_global_free_locks_(void);
+
 #endif
 
 #ifdef __cplusplus
diff --git evthread.c evthread.c
index 22d09ae..09507ac 100644
--- evthread.c
+++ evthread.c
@@ -370,6 +370,11 @@ evthread_setup_global_lock_(void *lock_, unsigned locktype, int enable_locks)
 }
 
 
+void
+evthread_destroy(void) {
+	event_global_free_locks_();
+}
+
 #ifndef EVTHREAD_EXPOSE_STRUCTS
 unsigned long
 _evthreadimpl_get_id()
diff --git evutil_rand.c evutil_rand.c
index f739965..37a3085 100644
--- evutil_rand.c
+++ evutil_rand.c
@@ -106,6 +106,13 @@ evutil_secure_rng_global_setup_locks_(const int enable_locks)
 	EVTHREAD_SETUP_GLOBAL_LOCK(arc4rand_lock, 0);
 	return 0;
 }
+
+void
+evutil_secure_rng_global_free_locks_(void) {
+	if (arc4rand_lock != NULL) {
+		EVTHREAD_FREE_LOCK(arc4rand_lock, 0);
+	}
+}
 #endif
 
 int
diff --git include/event2/thread.h include/event2/thread.h
index 3e7216d..7f5b17b 100644
--- include/event2/thread.h
+++ include/event2/thread.h
@@ -229,6 +229,9 @@ struct event_base;
  */
 int evthread_make_base_notifiable(struct event_base *base);
 
+/** destroy all possibly allocated global locks */
+void evthread_destroy_globals(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git signal.c signal.c
index 72c0847..00b024c 100644
--- signal.c
+++ signal.c
@@ -440,4 +440,11 @@ evsig_global_setup_locks_(const int enable_locks)
 	EVTHREAD_SETUP_GLOBAL_LOCK(evsig_base_lock, 0);
 	return 0;
 }
+
+void
+evsig_global_free_locks_(void) {
+	if (evsig_base_lock != NULL) {
+		EVTHREAD_FREE_LOCK(evsig_base_lock, 0);
+	}
+}
 #endif