From 1bf3b4a06d92e728b9e32d560b54cb41a562dde0 Mon Sep 17 00:00:00 2001 From: Todd Poynor Date: Thu, 2 May 2013 15:41:35 -0700 Subject: [PATCH] String8: ensure static init done prior to empty string reference Avoid NULL deref on static initialization of empty String8 objects prior to libutils static init. Change-Id: I3d420041ba62b97ed8c2dfd2532a2dcd72b84ff1 --- libs/utils/String8.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/utils/String8.cpp b/libs/utils/String8.cpp index 562f026f6..75daee9c2 100644 --- a/libs/utils/String8.cpp +++ b/libs/utils/String8.cpp @@ -48,12 +48,16 @@ int gDarwinIsReallyAnnoying; static inline char* getEmptyString() { + if (!gEmptyStringBuf) initialize_string8(); + gEmptyStringBuf->acquire(); return gEmptyString; } void initialize_string8() { + if (gEmptyStringBuf) return; + // HACK: This dummy dependency forces linking libutils Static.cpp, // which is needed to initialize String8/String16 classes. // These variables are named for Darwin, but are needed elsewhere too,