From: jochen@chromium.org Date: Wed, 26 Mar 2014 15:46:05 +0000 (+0000) Subject: Clean up ICU data tables on shutdown. X-Git-Tag: upstream/4.7.83~9987 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=53aa5b63a9ee971727d2ff62a25dacc3abf0286b;p=platform%2Fupstream%2Fv8.git Clean up ICU data tables on shutdown. This is only used by d8 if compiled with external data tables, or an embedder that uses external data tables and v8's version of ICU. BUG=none R=svenpanne@chromium.org LOG=n Review URL: https://codereview.chromium.org/210973007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20283 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/icu_util.cc b/src/icu_util.cc index 6441dbd..5ca9dbd 100644 --- a/src/icu_util.cc +++ b/src/icu_util.cc @@ -33,6 +33,7 @@ #if defined(V8_I18N_SUPPORT) #include +#include #include "unicode/putil.h" #include "unicode/udata.h" @@ -49,6 +50,17 @@ namespace v8 { namespace internal { +#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE +namespace { +char* g_icu_data_ptr = NULL; + +void free_icu_data_ptr() { + delete[] g_icu_data_ptr; +} + +} // namespace +#endif + bool InitializeICU(const char* icu_data_file) { #if !defined(V8_I18N_SUPPORT) return true; @@ -70,6 +82,8 @@ bool InitializeICU(const char* icu_data_file) { #elif ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE if (!icu_data_file) return false; + if (g_icu_data_ptr) return true; + FILE* inf = fopen(icu_data_file, "rb"); if (!inf) return false; @@ -77,15 +91,19 @@ bool InitializeICU(const char* icu_data_file) { size_t size = ftell(inf); rewind(inf); - char* addr = new char[size]; - if (fread(addr, 1, size, inf) != size) { - delete[] addr; + g_icu_data_ptr = new char[size]; + if (fread(g_icu_data_ptr, 1, size, inf) != size) { + delete[] g_icu_data_ptr; + g_icu_data_ptr = NULL; fclose(inf); return false; } fclose(inf); + + atexit(free_icu_data_ptr); + UErrorCode err = U_ZERO_ERROR; - udata_setCommonData(reinterpret_cast(addr), &err); + udata_setCommonData(reinterpret_cast(g_icu_data_ptr), &err); return err == U_ZERO_ERROR; #endif #endif