Permalink
Browse files

MB-5567: Release allocated memory during shutdown

Change-Id: Ic64e0b393caa2bc4588881690e408d58366be576
Reviewed-on: http://review.couchbase.org/17265
Reviewed-by: Dustin Sallings <dustin@spy.net>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information...
1 parent 1764fc2 commit a7ff8252afd8b6838985afb3a5116f0b75c3ea68 @trondn trondn committed Jun 14, 2012
Showing with 42 additions and 2 deletions.
  1. +1 −0 daemon/cache.c
  2. +20 −1 daemon/memcached.c
  3. +12 −1 daemon/thread.c
  4. +7 −0 utilities/engine_loader.c
  5. +2 −0 utilities/engine_loader.h
View
@@ -77,6 +77,7 @@ void cache_destroy(cache_t *cache) {
free(cache->name);
free(cache->ptr);
pthread_mutex_destroy(&cache->mutex);
+ free(cache);
}
void* cache_alloc(cache_t *cache) {
View
@@ -592,6 +592,19 @@ static void initialize_connections(void)
}
}
+static void destroy_connections(void)
+{
+ for (int ii = 0; ii < settings.maxconns; ++ii) {
+ if (connections.all[ii]) {
+ conn *c = connections.all[ii];
+ conn_destructor(c);
+ free(c);
+ }
+ }
+
+ free(connections.all);
+}
+
static conn *allocate_connection(void) {
conn *ret;
@@ -7761,7 +7774,7 @@ int main (int argc, char **argv) {
}
/* initialize main thread libevent instance */
- main_base = event_init();
+ main_base = event_base_new();
/* Load the storage engine */
ENGINE_HANDLE *engine_handle = NULL;
@@ -7899,5 +7912,11 @@ int main (int argc, char **argv) {
free(stats.listening_ports);
}
+ event_base_free(main_base);
+ release_independent_stats(default_independent_stats);
+ destroy_connections();
+
+ unload_engine();
+
return EXIT_SUCCESS;
}
View
@@ -240,7 +240,7 @@ static void setup_dispatcher(struct event_base *main_base,
*/
static void setup_thread(LIBEVENT_THREAD *me) {
me->type = GENERAL;
- me->base = event_init();
+ me->base = event_base_new();
if (! me->base) {
settings.extensions.logger->log(EXTENSION_LOG_WARNING, NULL,
"Can't allocate event base\n");
@@ -695,7 +695,18 @@ void threads_shutdown(void)
for (int ii = 0; ii < nthreads; ++ii) {
safe_close(threads[ii].notify[0]);
safe_close(threads[ii].notify[1]);
+ cache_destroy(threads[ii].suffix_cache);
+ event_base_free(threads[ii].base);
+
+ CQ_ITEM *it;
+ while ((it = cq_pop(threads[ii].new_conn_queue)) != NULL) {
+ cqi_free(it);
+ }
+ free(threads[ii].new_conn_queue);
}
+
+ free(thread_ids);
+ free(threads);
}
void notify_thread(LIBEVENT_THREAD *thread) {
@@ -17,6 +17,13 @@ static const char * const feature_descriptions[] = {
void *handle = NULL;
+void unload_engine(void)
+{
+ if (handle != NULL) {
+ dlclose(handle);
+ }
+}
+
bool load_engine(const char *soname,
SERVER_HANDLE_V1 *(*get_server_api)(void),
EXTENSION_LOGGER_DESCRIPTOR *logger,
@@ -9,6 +9,8 @@
#ifdef __cplusplus
extern "C" {
#endif
+MEMCACHED_PUBLIC_API void unload_engine(void);
+
MEMCACHED_PUBLIC_API bool load_engine(const char *soname,
SERVER_HANDLE_V1 *(*get_server_api)(void),
EXTENSION_LOGGER_DESCRIPTOR *logger,

0 comments on commit a7ff825

Please sign in to comment.