CMake configuration files are intended to be used by other projects to find the library. Specifically the CMake find_package command can use it to find all files related to the project. The idea is to support 2 different CMake configuration files for Libevent. One if you simply build libevent that is generated for the build tree. And a second one that is generated for an install target that will be installed on the system and point to where on the system the lib files and such can be find. So for instance, in the build tree the config would set the cmake variable `LIBEVENT_INCLUDE_DIRS` to `/path/to/libevent/build/include`. And for the system config it would be set to `/usr/local/include` (or whatever target the user chose when running cmake). 27bd9fa changed this behavior so that both configs would point to the system wide path `/usr/local/include` This meant that projects just wanting to import directly for the build tree would fail.
For more info look at 92a359e ("be_pair: release shared lock with the latest of bufferevent_pair")
This will allow to use library event after event_free_debug_globals_locks()/libevent_global_shutdown() without invalid read/write's.
Then next code sample will use free'd lock: evthread_use_pthreads(); ... assert(!bufferevent_pair_new(base, BEV_OPT_THREADSAFE, pair)); ... bufferevent_free(pair); # refcnt == 0 -> unlink bufferevent_free(pair); # refcnt == 0 -> unlink ... event_base_free() -> finalizers -> EVTHREAD_FREE_LOCK(bev1->lock) -> BEV_LOCK(bev2->lock) <-- *already freed* While if you will reverse the order: bufferevent_free(pair); # refcnt == 0 -> unlink bufferevent_free(pair); # refcnt == 0 -> unlink ... event_base_free() -> finalizers -> BEV_LOCK(bev2->lock)/!own_lock/BEV_UNLOCK(bev2->lock) -> EVTHREAD_FREE_LOCK(bev1->lock) (own_lock) It is ok now, but I guess that it will be better to relax order of freeing pairs.
This will avoid leaking of event_debug_map_HT_GROW I buildin it into libevent_glboal_shutdown() because event_disable_debug_mode() -> event_free_debug_globals() -> event_free_debug_globals_locks() will clean event_debug_map_lock_ that used in event_disable_debug_mode().
name_##HT_CLEAR calls name_##HT_INIT that reset hth_table_length to 0.
For this fix, we need to make sure that passing too-large inputs to the evbuffer functions can't make us do bad things with the heap. Also, lower the maximum chunk size to the lower of off_t, size_t maximum. This is necessary since otherwise we could get into an infinite loop if we make a chunk that 'misalign' cannot index into.