diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2012-02-17 14:54:58 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2012-02-17 14:54:58 -0800 |
commit | 51da4856e2ff124d8d5ad7a4a6ca844c81825133 (patch) | |
tree | 801c4e75be2bd9469f5d98f480a20d2dce4021e3 /iothread.cpp | |
parent | 3b56c58f00c382ceb83eac78baede3a4b76c08a0 (diff) |
Squash a leak in LRU caches
Diffstat (limited to 'iothread.cpp')
-rw-r--r-- | iothread.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/iothread.cpp b/iothread.cpp index b302c673..ee122369 100644 --- a/iothread.cpp +++ b/iothread.cpp @@ -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(); |