Author: tschoening
Date: Tue Dec 15 17:12:30 2015
New Revision: 1720199

URL: http://svn.apache.org/viewvc?rev=1720199&view=rev
Log:
LOGCXX-461: SocketAppender creates memory issue for log4j server.

Modified:
    incubator/log4cxx/trunk/src/main/cpp/objectoutputstream.cpp
    incubator/log4cxx/trunk/src/main/cpp/socketappender.cpp
    
incubator/log4cxx/trunk/src/main/include/log4cxx/helpers/objectoutputstream.h

Modified: incubator/log4cxx/trunk/src/main/cpp/objectoutputstream.cpp
URL: 
http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/cpp/objectoutputstream.cpp?rev=1720199&r1=1720198&r2=1720199&view=diff
==============================================================================
--- incubator/log4cxx/trunk/src/main/cpp/objectoutputstream.cpp (original)
+++ incubator/log4cxx/trunk/src/main/cpp/objectoutputstream.cpp Tue Dec 15 
17:12:30 2015
@@ -33,7 +33,8 @@ IMPLEMENT_LOG4CXX_OBJECT(ObjectOutputStr
 ObjectOutputStream::ObjectOutputStream(OutputStreamPtr outputStream, Pool& p)
        :       os(outputStream),
                utf8Encoder(CharsetEncoder::getUTF8Encoder()),
-               objectHandle(0x7E0000),
+               objectHandleDefault(0x7E0000),
+               objectHandle(objectHandleDefault),
                classDescriptions(new ClassDescriptionMap())
 {
        char start[] = { static_cast<char>(0xAC), static_cast<char>(0xED), 
0x00, 0x05 };
@@ -56,6 +57,16 @@ void ObjectOutputStream::flush(Pool& p)
        os->flush(p);
 }
 
+void ObjectOutputStream::reset(Pool& p)
+{
+       os->flush(p);
+       writeByte(TC_RESET, p);
+       os->flush(p);
+
+       objectHandle = objectHandleDefault;
+       classDescriptions->clear();
+}
+
 void ObjectOutputStream::writeObject(const LogString& val, Pool& p)
 {
        objectHandle++;
@@ -81,7 +92,6 @@ void ObjectOutputStream::writeObject(con
        os->write(dataBuf,      p);
 }
 
-
 void ObjectOutputStream::writeObject(const MDC::Map& val, Pool& p)
 {
        //
@@ -141,8 +151,6 @@ void ObjectOutputStream::writeUTFString(
        os->write(dataBuf, p);
 }
 
-
-
 void ObjectOutputStream::writeByte(char val, Pool& p)
 {
        ByteBuffer buf(&val, 1);

Modified: incubator/log4cxx/trunk/src/main/cpp/socketappender.cpp
URL: 
http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/cpp/socketappender.cpp?rev=1720199&r1=1720198&r2=1720199&view=diff
==============================================================================
--- incubator/log4cxx/trunk/src/main/cpp/socketappender.cpp (original)
+++ incubator/log4cxx/trunk/src/main/cpp/socketappender.cpp Tue Dec 15 17:12:30 
2015
@@ -116,6 +116,7 @@ void SocketAppender::append(const spi::L
        {
                event->write(*oos, p);
                oos->flush(p);
+               oos->reset(p);
        }
        catch(std::exception& e)
        {

Modified: 
incubator/log4cxx/trunk/src/main/include/log4cxx/helpers/objectoutputstream.h
URL: 
http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/include/log4cxx/helpers/objectoutputstream.h?rev=1720199&r1=1720198&r2=1720199&view=diff
==============================================================================
--- 
incubator/log4cxx/trunk/src/main/include/log4cxx/helpers/objectoutputstream.h 
(original)
+++ 
incubator/log4cxx/trunk/src/main/include/log4cxx/helpers/objectoutputstream.h 
Tue Dec 15 17:12:30 2015
@@ -43,6 +43,8 @@ namespace log4cxx
 
                                void close(Pool& p);
                                void flush(Pool& p);
+                               void reset(Pool& p);
+
                                void writeObject(const LogString&, Pool& p);
                                void writeUTFString(const std::string&, Pool& 
p);
                                void writeObject(const MDC::Map& mdc, Pool& p);
@@ -55,8 +57,8 @@ namespace log4cxx
                                                                                
Pool&   p);
                                void writeNull(Pool& p);
 
-                               enum { STREAM_MAGIC             = 0xACED };
-                               enum { STREAM_VERSION   = 5 };
+                               enum { STREAM_MAGIC             = 0xACED        
};
+                               enum { STREAM_VERSION   = 5                     
};
                                enum
                                {
                                        TC_NULL                 = 0x70,
@@ -67,7 +69,8 @@ namespace log4cxx
                                        TC_ARRAY                = 0x75,
                                        TC_CLASS                = 0x76,
                                        TC_BLOCKDATA    = 0x77,
-                                       TC_ENDBLOCKDATA = 0x78
+                                       TC_ENDBLOCKDATA = 0x78,
+                                       TC_RESET                = 0x79
                                };
                                enum
                                {
@@ -82,11 +85,12 @@ namespace log4cxx
                                ObjectOutputStream(const ObjectOutputStream&);
                                ObjectOutputStream& operator=(const 
ObjectOutputStream&);
 
-                               OutputStreamPtr os;
-                               log4cxx::helpers::CharsetEncoderPtr utf8Encoder;
-                               unsigned int objectHandle;
-                               typedef std::map<std::string, unsigned int> 
ClassDescriptionMap;
-                               ClassDescriptionMap* classDescriptions;
+                                               OutputStreamPtr                 
                        os;
+                                               
log4cxx::helpers::CharsetEncoderPtr     utf8Encoder;
+                               const   unsigned int                            
                objectHandleDefault;
+                                               unsigned int                    
                        objectHandle;
+                               typedef std::map<std::string, unsigned int>     
ClassDescriptionMap;
+                                               ClassDescriptionMap*            
                classDescriptions;
                };
 
                LOG4CXX_PTR_DEF(ObjectOutputStream);


Reply via email to