Squash a leak in LRU caches

This commit is contained in:
ridiculousfish 2012-02-17 14:54:58 -08:00
parent 3b56c58f00
commit 51da4856e2
4 changed files with 14 additions and 7 deletions

View file

@ -1005,7 +1005,7 @@ static int try_remove( env_node_t *n,
has_changed = 1;
}
n->env.erase(result);
n->env.erase(result);
delete v;
return 1;
}

View file

@ -624,7 +624,9 @@ void history_t::save_internal()
break;
}
}
/* Make sure we clear all nodes, since this doesn't happen automatically */
lru.evict_all_nodes();
if( fclose( out ) || !ok )
{

View file

@ -142,7 +142,7 @@ int iothread_perform_base(int (*handler)(void *), void (*completionCallback)(voi
iothread_init();
/* Create and initialize a request. */
struct ThreadedRequest_t *req = (struct ThreadedRequest_t *)malloc(sizeof *req);
struct ThreadedRequest_t *req = new ThreadedRequest_t();
req->next = NULL;
req->handler = handler;
req->completionCallback = completionCallback;
@ -186,10 +186,12 @@ void iothread_service_completion(void) {
s_active_thread_count -= 1;
/* Handle the request */
if (req && req->completionCallback) {
req->completionCallback(req->context, req->handlerResult);
}
if (req) {
if (req->completionCallback)
req->completionCallback(req->context, req->handlerResult);
delete req;
}
/* Maybe spawn another thread, if there's more work to be done. */
VOMIT_ON_FAILURE(pthread_mutex_lock(&s_request_queue_lock));
iothread_spawn_if_needed();

3
lru.h
View file

@ -101,6 +101,9 @@ class lru_cache_t {
mouth.prev = mouth.next = &mouth;
}
/** Note that we do not define a destructor. We cannot evict all nodes (even though they typically need to be deleted by their creator). */
/** Returns the node for a given key, or NULL */
node_type_t *get_node(const wcstring &key) {
node_type_t *result = NULL;