From 1caec7cb16e08c47507d2d25ef1b9672013b5339 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 20 Jun 2014 00:00:06 +0900 Subject: [PATCH] h2load: Fix memory leak detected by LeakSanitizer --- src/h2load.cc | 14 ++++++++++---- src/h2load.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/h2load.cc b/src/h2load.cc index 79f02677..81e16a90 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -315,7 +315,7 @@ int Client::on_write() Worker::Worker(uint32_t id, SSL_CTX *ssl_ctx, size_t req_todo, size_t nclients, Config *config) : stats{0}, evbase(event_base_new()), ssl_ctx(ssl_ctx), config(config), - id(id), term_timer_started(false) + term_timer(nullptr), id(id) { stats.req_todo = req_todo; progress_interval = std::max((size_t)1, req_todo / 10); @@ -326,6 +326,9 @@ Worker::Worker(uint32_t id, SSL_CTX *ssl_ctx, size_t req_todo, size_t nclients, Worker::~Worker() { + if(term_timer) { + event_free(term_timer); + } event_base_free(evbase); } @@ -350,11 +353,11 @@ void term_timeout_cb(evutil_socket_t fd, short what, void *arg) void Worker::schedule_terminate() { - if(term_timer_started) { + if(term_timer) { return; } - term_timer_started = true; - auto term_timer = evtimer_new(evbase, term_timeout_cb, this); + + term_timer = evtimer_new(evbase, term_timeout_cb, this); timeval timeout = { 0, 0 }; evtimer_add(term_timer, &timeout); } @@ -998,6 +1001,9 @@ int main(int argc, char **argv) << worker.stats.bytes_head << " bytes headers, " << worker.stats.bytes_body << " bytes data" << std::endl; + + SSL_CTX_free(ssl_ctx); + return 0; } diff --git a/src/h2load.h b/src/h2load.h index 8327f478..9943d5bb 100644 --- a/src/h2load.h +++ b/src/h2load.h @@ -113,9 +113,9 @@ struct Worker { event_base *evbase; SSL_CTX *ssl_ctx; Config *config; + event *term_timer; size_t progress_interval; uint32_t id; - bool term_timer_started; Worker(uint32_t id, SSL_CTX *ssl_ctx, size_t nreq_todo, size_t nclients, Config *config);