summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jni_internal.cc6
-rw-r--r--src/stl_util.h12
2 files changed, 14 insertions, 4 deletions
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 5ab86920e1..292d1e463a 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -20,6 +20,7 @@
#include "object.h"
#include "runtime.h"
#include "scoped_jni_thread_state.h"
+#include "stl_util.h"
#include "stringpiece.h"
#include "thread.h"
@@ -555,10 +556,7 @@ class Libraries {
}
~Libraries() {
- // Delete our map values. (The keys will be cleaned up by the map itself.)
- for (It it = libraries_.begin(); it != libraries_.end(); ++it) {
- delete it->second;
- }
+ STLDeleteValues(&libraries_);
}
SharedLibrary* Get(const std::string& path) {
diff --git a/src/stl_util.h b/src/stl_util.h
index 024f1629f8..5fcf089bf4 100644
--- a/src/stl_util.h
+++ b/src/stl_util.h
@@ -42,6 +42,18 @@ void STLDeleteElements(T *container) {
container->clear();
}
+// Given an STL container consisting of (key, value) pairs, STLDeleteValues
+// deletes all the "value" components and clears the container. Does nothing
+// in the case it's given a NULL pointer.
+template <class T>
+void STLDeleteValues(T *v) {
+ if (!v) return;
+ for (typename T::iterator i = v->begin(); i != v->end(); ++i) {
+ delete i->second;
+ }
+ v->clear();
+}
+
} // namespace art
#endif // ART_SRC_STL_UTIL_H_