From 52be93c54bfedf16bb86472c03b6833d2be0efd1 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Wed, 29 Jun 2016 10:14:57 +0100 Subject: [PATCH] dmsetup: fix timestamp leak With a single report (--count=1) no timerfd is set up and the cycle and current timestamps should be freed during the single call to _update_interval_times(). --- tools/dmsetup.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/dmsetup.c b/tools/dmsetup.c index 03e25198a..8ba12ddbe 100644 --- a/tools/dmsetup.c +++ b/tools/dmsetup.c @@ -703,13 +703,16 @@ static int _update_interval_times(void) { static struct dm_timestamp *this_timestamp = NULL; uint64_t delta_t, interval_num = _interval_num(); - int r = 0; + int r = 1; /* * Clock shutdown for exit - nothing to do. */ - if (_timer_fd == TIMER_STOPPED && !_cycle_timestamp) - return 1; + if ((_timer_fd == TIMER_STOPPED) && !_cycle_timestamp) + goto out; + + /* clock is running */ + r = 0; /* * Current timestamp. If _new_interval is set this is used as @@ -780,7 +783,8 @@ static int _update_interval_times(void) r = 1; out: - if (!r || _timer_fd == TIMER_STOPPED) { + /* timer stopped or never started */ + if (!r || _timer_fd < 0) { /* The _cycle_timestamp has not yet been allocated if we * fail to obtain this_timestamp on the first interval. */