Coder Social home page Coder Social logo

Comments (3)

qidu avatar qidu commented on June 22, 2024

We can add following patches to fix the bug
--------------------------------------------------------------------patch of signal.c------------------------------------------------------------------

--- /root/dev/orig/libevent-2.0.21-stable/signal.c  2012-11-02 23:57:00.000000000 +0800
+++ /root/dev/libevent-2.0.21-stable/signal.c   2013-04-16 15:27:31.000000000 +0800
@@ -439,7 +439,14 @@
 int
 evsig_global_setup_locks_(const int enable_locks)
 {
    EVTHREAD_SETUP_GLOBAL_LOCK(evsig_base_lock, 0);
    return 0;
 }
+
+int
+evsig_global_free_locks_(const int enable_locks)
+{
+   EVTHREAD_FREE_LOCK(evsig_base_lock, 0);
+}
 #endif

--------------------------------------------------------------------patch of evutil_rand.c------------------------------------------------------------------

--- /root/dev/orig/libevent-2.0.21-stable/evutil_rand.c 2012-08-02 23:36:53.000000000 +0800
+++ /root/dev/libevent-2.0.21-stable/evutil_rand.c  2013-04-16 15:27:19.000000000 +0800
@@ -118,9 +118,16 @@
 int
 evutil_secure_rng_global_setup_locks_(const int enable_locks)
 {
    EVTHREAD_SETUP_GLOBAL_LOCK(arc4rand_lock, 0);
    return 0;
 }
+
+int
+evutil_secure_rng_global_free_locks_(const int enable_locks)
+{
+   EVTHREAD_FREE_LOCK(arc4rand_lock, 0);
+}
 #endif

 int

------------------------------------------------------------patch of event.c---------------------------------------------------------------------------------

--- /root/dev/orig/libevent-2.0.21-stable/event.c   2012-11-17 08:22:19.000000000 +0800
+++ /root/dev/libevent-2.0.21-stable/event.c    2013-04-16 15:30:15.000000000 +0800
@@ -788,7 +789,12 @@
    EVTHREAD_FREE_LOCK(base->th_base_lock, EVTHREAD_LOCKTYPE_RECURSIVE);
    EVTHREAD_FREE_COND(base->current_event_cond);

+   if(!current_base) {
+       event_global_free_locks_(0);
+   }
+
    mm_free(base);
 }

 /* reinitialize the event base after a fork */
@@ -2887,6 +2895,16 @@
        return -1;
    return 0;
 }
+
+int 
+event_global_free_locks_(const int enable_locks)
+{
+   evutil_secure_rng_global_free_locks_(0);
+   evsig_global_free_locks_(0);
+#ifndef _EVENT_DISABLE_DEBUG_MODE
+   EVTHREAD_FREE_LOCK(_event_debug_map_lock, 0);
+#endif
+}
 #endif

 void

from libevent.

nmathewson avatar nmathewson commented on June 22, 2024

This part is broken:

+   if(!current_base) {
+       event_global_free_locks_(0);
+   }

If someone creates two event_bases, and frees the second one, this will free the global locks.

Libevent 2.1 already has a fix for this in the libevent_global_shutdown() function.

from libevent.

qidu avatar qidu commented on June 22, 2024

OK, i see, current_base is not a right flag for releasing global locks.
Calling the external interface "libevent_global_shutdown" explicitly would be better for users.
Thanks!

from libevent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.