From f7399bf929f401d4e1aa40f4f7a2265e2cdedc39 Mon Sep 17 00:00:00 2001 From: Jeffrey Yasskin Date: Sun, 7 Mar 2010 06:55:35 +0000 Subject: Avoid leaking CompileUnits and DbgScopes from DwarfDebug. Leaks found by Valgrind! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97906 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/STLExtras.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include') diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h index 32cf459..8dbf790 100644 --- a/include/llvm/ADT/STLExtras.h +++ b/include/llvm/ADT/STLExtras.h @@ -279,6 +279,28 @@ static inline void array_pod_sort(IteratorTy Start, IteratorTy End, qsort(&*Start, End-Start, sizeof(*Start), Compare); } +//===----------------------------------------------------------------------===// +// Extra additions to +//===----------------------------------------------------------------------===// + +/// For a container of pointers, deletes the pointers and then clears the +/// container. +template +void DeleteContainerPointers(Container &C) { + for (typename Container::iterator I = C.begin(), E = C.end(); I != E; ++I) + delete *I; + C.clear(); +} + +/// In a container of pairs (usually a map) whose second element is a pointer, +/// deletes the second elements and then clears the container. +template +void DeleteContainerSeconds(Container &C) { + for (typename Container::iterator I = C.begin(), E = C.end(); I != E; ++I) + delete I->second; + C.clear(); +} + } // End llvm namespace #endif -- cgit v1.1