You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Mihai Rusu <di...@roedu.net> on 2005/10/21 18:17:54 UTC
[PATCH][RFC] change "static" to "auto" for Transcoder::decode() decoder and CharsetDecoder::getDefaultDecoder() decoder
Hi
The following patch is a dirty hack and I assume you will want to have
it in a totally different way. But it fixes the crash I get. So far it
seems that Transcoder::decode() can get called (from the destructors of
static objects) even after it's internal static variables get destroyed
(thus decrementing the reference count, thus destroying the referenced
object eventually thus having the codes dereference an invalid pointer).
The problem is also present in the ::encode() functions and their
"encoder" variable (but it didnt bite my program yet, so I left it
there).
Index: src/transcoder.cpp
===================================================================
--- src/transcoder.cpp (revision 694)
+++ src/transcoder.cpp (revision 695)
@@ -52,7 +52,8 @@
* internal string.
*/
void Transcoder::decode(const char* src, size_t len, LogString& dst) {
- static CharsetDecoderPtr decoder(CharsetDecoder::getDefaultDecoder());
+ /* FIXME: find a better solution to have decoder initilized only once */
+ CharsetDecoderPtr decoder(CharsetDecoder::getDefaultDecoder());
if (len > 0) {
ByteBuffer buf((char*) src, len);
while(buf.remaining() > 0) {
Index: src/charsetdecoder.cpp
===================================================================
--- src/charsetdecoder.cpp (revision 694)
+++ src/charsetdecoder.cpp (revision 695)
@@ -432,8 +432,10 @@
}
CharsetDecoderPtr CharsetDecoder::getDefaultDecoder() {
+/* FIXME: find a better solution to initilize this once
static CharsetDecoderPtr decoder(createDefaultDecoder());
- return decoder;
+ */
+ return createDefaultDecoder();
}
#if LOG4CXX_HAS_WCHAR_T
--
Mihai RUSU Email: dizzy@roedu.net
GPG : http://dizzy.roedu.net/dizzy-gpg.txt WWW: http://dizzy.roedu.net
"Linux is obsolete" -- AST