From 1970cc0ec81edf51c6887f003b79920eb1c84d40 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Fri, 28 Sep 2018 14:57:10 +0200 Subject: [PATCH] common: fix memory leaks in WeightedPriorityQueue. Fixes: http://tracker.ceph.com/issues/36248 Signed-off-by: Radoslaw Zarzynski (cherry picked from commit 61395d44010f0ac1c183d030b244ae1ec0c8b99a) --- src/common/WeightedPriorityQueue.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/common/WeightedPriorityQueue.h b/src/common/WeightedPriorityQueue.h index c51a2b1f4450..7c891ee6f46a 100644 --- a/src/common/WeightedPriorityQueue.h +++ b/src/common/WeightedPriorityQueue.h @@ -67,8 +67,11 @@ class WeightedPriorityQueue : public OpQueue K key; // klass ListPairs lp; Klass(K& k) : - key(k) - {} + key(k) { + } + ~Klass() { + lp.clear_and_dispose(DelItem()); + } friend bool operator< (const Klass &a, const Klass &b) { return a.key < b.key; } friend bool operator> (const Klass &a, const Klass &b) @@ -129,8 +132,11 @@ class WeightedPriorityQueue : public OpQueue Kit next; SubQueue(unsigned& p) : key(p), - next(klasses.begin()) - {} + next(klasses.begin()) { + } + ~SubQueue() { + klasses.clear_and_dispose(DelItem()); + } friend bool operator< (const SubQueue &a, const SubQueue &b) { return a.key < b.key; } friend bool operator> (const SubQueue &a, const SubQueue &b) @@ -195,8 +201,11 @@ class WeightedPriorityQueue : public OpQueue Queue() : total_prio(0), max_cost(0), - size(0) - {} + size(0) { + } + ~Queue() { + queues.clear_and_dispose(DelItem()); + } bool empty() const { return !size; } -- 2.47.3