Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: src/icu_util.cc

Issue 210973007: Clean up ICU data tables on shutdown. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/icu_util.cc
diff --git a/src/icu_util.cc b/src/icu_util.cc
index 6441dbdd9f5fd98392a720d174fb7b4cebed7510..5ca9dbd5032e7ff8e05ce5544c723b17d9305753 100644
--- a/src/icu_util.cc
+++ b/src/icu_util.cc
@@ -33,6 +33,7 @@
#if defined(V8_I18N_SUPPORT)
#include <stdio.h>
+#include <stdlib.h>
#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);
Sven Panne 2014/03/26 07:44:47 Hmmm, using atexit is always a kind of a hack, and
+
UErrorCode err = U_ZERO_ERROR;
- udata_setCommonData(reinterpret_cast<void*>(addr), &err);
+ udata_setCommonData(reinterpret_cast<void*>(g_icu_data_ptr), &err);
return err == U_ZERO_ERROR;
#endif
#endif
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698