util: don't leak resources from SumTree
This fixes the resource-leaking "should never happen" case when no element is found by returning a notfound member. Found by Coverity Scan, CID 25555. Change-Id: I9055ae0a3b31e61f3a8e3b098ec5613c3b5535f6
This commit is contained in:
@ -108,6 +108,7 @@ private:
|
|||||||
//! Tree depth: nodes at level m_depth are leaf nodes, others are inner nodes
|
//! Tree depth: nodes at level m_depth are leaf nodes, others are inner nodes
|
||||||
unsigned m_depth;
|
unsigned m_depth;
|
||||||
public:
|
public:
|
||||||
|
T notfound; //! Returned if no element was found.
|
||||||
SumTree() : m_root(new Bucket), m_depth(0) {}
|
SumTree() : m_root(new Bucket), m_depth(0) {}
|
||||||
~SumTree() { delete m_root; }
|
~SumTree() { delete m_root; }
|
||||||
//! Adds a copy of a new element to the tree. The copy is created internally.
|
//! Adds a copy of a new element to the tree. The copy is created internally.
|
||||||
@ -244,7 +245,7 @@ T SumTree<T, BUCKETSIZE>::remove(typename T::size_type pos, Bucket *node, typena
|
|||||||
|
|
||||||
// this should never happen
|
// this should never happen
|
||||||
assert(0);
|
assert(0);
|
||||||
return T();
|
return notfound;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, unsigned BUCKETSIZE>
|
template <typename T, unsigned BUCKETSIZE>
|
||||||
@ -282,7 +283,7 @@ T& SumTree<T, BUCKETSIZE>::get(typename T::size_type pos, Bucket *node, typename
|
|||||||
|
|
||||||
// this should never happen
|
// this should never happen
|
||||||
assert(0);
|
assert(0);
|
||||||
return *(new T);
|
return notfound;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user