From 879b50ecc24c926dea9e12d9f58a1d1a040a2d94 Mon Sep 17 00:00:00 2001
From: Adam Wardynski <award@.(B-4.4.46a)>
Date: Sat, 20 Nov 2010 18:53:05 +0100
Subject: [PATCH] Poor man's autocleanup of ICU in the test suite. So tools
 like valgrind don't get too excited that there's still reachable but not
 freed memory.

---
 tests/main.cpp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/tests/main.cpp b/tests/main.cpp
index 18c0325..0cbc1e4 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -1,5 +1,6 @@
 //#define BOOST_TEST_MODULE master
 #include <boost/test/included/unit_test.hpp>
+#include <unicode/uclean.h>
 
 BOOST_AUTO_TEST_CASE(test_test)
 {
@@ -7,6 +8,20 @@ BOOST_AUTO_TEST_CASE(test_test)
 	BOOST_CHECK(a == 0);
 }
 
+//Auto cleanup of ICU with a static variable destructor.
+//ICU can hold onto some memory resources until program exit,
+//when the system is reclaiming them as usual. This is not a memory
+//leak but makes tools like valgrind all excited that
+//there is memory which is "still reachable but not freed."
+//So, the below will perform icu cleanup before test program exit.
+static struct ICU_cleaner
+{
+	~ICU_cleaner()
+	{
+		u_cleanup();
+	}
+} the_cleaner;
+
 boost::unit_test::test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[])
 {
 	return 0;
-- 
GitLab