From 23a85d7a711f1cd5bf7170ff2a4106d00995c079 Mon Sep 17 00:00:00 2001
From: Robert Middleton <robert.middleton@rm5248.com>
Date: Mon, 7 Sep 2020 17:24:49 -0400
Subject: [PATCH] Fix segfault on OSX when destructor called

---
 src/main/cpp/logstream.cpp                            | 3 +++
 src/main/include/CMakeLists.txt                       | 2 ++
 src/main/include/log4cxx/private/log4cxx_private.h.in | 1 +
 3 files changed, 6 insertions(+)

diff --git a/src/main/cpp/logstream.cpp b/src/main/cpp/logstream.cpp
index de9a763b..29c3bcfa 100644
--- a/src/main/cpp/logstream.cpp
+++ b/src/main/cpp/logstream.cpp
@@ -34,6 +34,9 @@ logstream_base::logstream_ios_base::logstream_ios_base(std::ios_base::fmtflags i
 	//        releases a pointer that was not initialized in the constructor.
 	//
 	memset(this, 0, sizeof(*this));
+#endif
+#if LOG4CXX_INIT_IOS_BASE
+	init(NULL);
 #endif
 	flags(initval);
 	precision(initsize);
diff --git a/src/main/include/CMakeLists.txt b/src/main/include/CMakeLists.txt
index d1a0bb21..a8b0f400 100644
--- a/src/main/include/CMakeLists.txt
+++ b/src/main/include/CMakeLists.txt
@@ -34,8 +34,10 @@ else()
 endif()
 option(LOG4CXX_WCHAR_T "Enable wchar_t API methods" ON)
 option(LOG4CXX_UNICHAR "Enable UniChar API methods" OFF)
+set(INIT_IOS_BASE 0)
 if(APPLE)
 option(LOG4CXX_CFSTRING "Enable CFString API methods, requires Mac OS/X CoreFoundation" OFF)
+set(INIT_IOS_BASE 1)
 endif()
 set(CHAR_API 1)
 foreach(varName WCHAR_T  UNICHAR  CFSTRING )
diff --git a/src/main/include/log4cxx/private/log4cxx_private.h.in b/src/main/include/log4cxx/private/log4cxx_private.h.in
index e21f4d80..53e59efa 100644
--- a/src/main/include/log4cxx/private/log4cxx_private.h.in
+++ b/src/main/include/log4cxx/private/log4cxx_private.h.in
@@ -40,6 +40,7 @@
 #define LOG4CXX_HAS_MBSRTOWCS @HAS_MBSRTOWCS@
 #define LOG4CXX_HAS_WCSTOMBS @HAS_WCSTOMBS@
 #define LOG4CXX_HAS_FWIDE @HAS_FWIDE@
+#define LOG4CXX_INIT_IOS_BASE @INIT_IOS_BASE@
 
 #define LOG4CXX_CHARSET_UTF8 @CHARSET_UTF8@
 #define LOG4CXX_CHARSET_ISO88591 @CHARSET_ISO88591@
