You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sc...@apache.org on 2015/02/28 02:55:32 UTC

svn commit: r1662880 - in /xerces/c/branches/xerces-3.1/src/xercesc: framework/LocalFileFormatTarget.cpp internal/BinFileOutputStream.cpp util/BinFileInputStream.cpp

Author: scantor
Date: Sat Feb 28 01:55:31 2015
New Revision: 1662880

URL: http://svn.apache.org/r1662880
Log:
XERCESC-2024,XERCESC-2031

Modified:
    xerces/c/branches/xerces-3.1/src/xercesc/framework/LocalFileFormatTarget.cpp
    xerces/c/branches/xerces-3.1/src/xercesc/internal/BinFileOutputStream.cpp
    xerces/c/branches/xerces-3.1/src/xercesc/util/BinFileInputStream.cpp

Modified: xerces/c/branches/xerces-3.1/src/xercesc/framework/LocalFileFormatTarget.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.1/src/xercesc/framework/LocalFileFormatTarget.cpp?rev=1662880&r1=1662879&r2=1662880&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.1/src/xercesc/framework/LocalFileFormatTarget.cpp (original)
+++ xerces/c/branches/xerces-3.1/src/xercesc/framework/LocalFileFormatTarget.cpp Sat Feb 28 01:55:31 2015
@@ -66,17 +66,27 @@ LocalFileFormatTarget::LocalFileFormatTa
 
 LocalFileFormatTarget::~LocalFileFormatTarget()
 {
-    try
+    if (fSource && fSource != (FileHandle) XERCES_Invalid_File_Handle)
     {
-        // flush remaining buffer before destroy
-        XMLPlatformUtils::writeBufferToFile(fSource, fIndex, fDataBuf, fMemoryManager);
-
-        if (fSource)
-          XMLPlatformUtils::closeFile(fSource, fMemoryManager);
-    }
-    catch (...)
-    {
-      // There is nothing we can do about it here.
+        try
+        {
+            // flush remaining buffer before destroy
+            flush();
+        }
+        catch (...)
+        {
+            // There is nothing we can do about it here.
+        }
+        // XERCESC-2024: use separate try/catch so that we close the handle
+        // even when flush() failed (e.g. because of a disk full)
+        try
+        {
+            XMLPlatformUtils::closeFile(fSource, fMemoryManager);
+        }
+        catch (...)
+        {
+            // There is nothing we can do about it here.
+        }
     }
 
     fMemoryManager->deallocate(fDataBuf);//delete [] fDataBuf;
@@ -84,47 +94,42 @@ LocalFileFormatTarget::~LocalFileFormatT
 
 void LocalFileFormatTarget::flush()
 {
-  XMLPlatformUtils::writeBufferToFile(fSource, fIndex, fDataBuf, fMemoryManager);
-  fIndex = 0;
+    XMLPlatformUtils::writeBufferToFile(fSource, fIndex, fDataBuf, fMemoryManager);
+    fIndex = 0;
 }
 
 void LocalFileFormatTarget::writeChars(const XMLByte* const toWrite
                                      , const XMLSize_t count
                                      , XMLFormatter * const)
 {
-    if (count)
+    if (count == 0)
+        return;
+    if (count < MAX_BUFFER_SIZE)
     {
-      if (count < MAX_BUFFER_SIZE)
-      {
         // If we don't have enough space, see if we can grow the buffer.
         //
         if (fIndex + count > fCapacity && fCapacity < MAX_BUFFER_SIZE)
-          ensureCapacity (count);
+            ensureCapacity (count);
 
         // If still not enough space, flush the buffer.
         //
         if (fIndex + count > fCapacity)
-        {
-          XMLPlatformUtils::writeBufferToFile(fSource, fIndex, fDataBuf, fMemoryManager);
-          fIndex = 0;
-        }
+            flush();
 
         memcpy(&fDataBuf[fIndex], toWrite, count * sizeof(XMLByte));
         fIndex += count;
-      }
-      else
-      {
+    }
+    else
+    {
+        // block is too big to cache, flush the current cache...
+        //
         if (fIndex)
-        {
-          XMLPlatformUtils::writeBufferToFile(fSource, fIndex, fDataBuf, fMemoryManager);
-          fIndex = 0;
-        }
+            flush();
 
+        //... then write the data directly to disk
+        //
         XMLPlatformUtils::writeBufferToFile(fSource, count, toWrite, fMemoryManager);
-      }
     }
-
-    return;
 }
 
 void LocalFileFormatTarget::ensureCapacity(const XMLSize_t extraNeeded)

Modified: xerces/c/branches/xerces-3.1/src/xercesc/internal/BinFileOutputStream.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.1/src/xercesc/internal/BinFileOutputStream.cpp?rev=1662880&r1=1662879&r2=1662880&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.1/src/xercesc/internal/BinFileOutputStream.cpp (original)
+++ xerces/c/branches/xerces-3.1/src/xercesc/internal/BinFileOutputStream.cpp Sat Feb 28 01:55:31 2015
@@ -34,12 +34,6 @@ XERCES_CPP_NAMESPACE_BEGIN
 // ---------------------------------------------------------------------------
 //  BinFileOutputStream: Constructors and Destructor
 // ---------------------------------------------------------------------------
-BinFileOutputStream::~BinFileOutputStream()
-{
-    if (getIsOpen())
-        XMLPlatformUtils::closeFile(fSource, fMemoryManager);
-}
-
 BinFileOutputStream::BinFileOutputStream(const XMLCh*   const fileName
                                          , MemoryManager* const manager)
 
@@ -55,6 +49,21 @@ BinFileOutputStream::BinFileOutputStream
 {
 }
 
+BinFileOutputStream::~BinFileOutputStream()
+{
+    if (getIsOpen())
+    {
+        try
+        {
+            XMLPlatformUtils::closeFile(fSource, fMemoryManager);
+        }
+        catch (...)
+        {
+            // There is nothing we can do about it here.
+        }
+    }
+}
+
 // ---------------------------------------------------------------------------
 //  BinFileOutputStream: Getter methods
 // ---------------------------------------------------------------------------

Modified: xerces/c/branches/xerces-3.1/src/xercesc/util/BinFileInputStream.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.1/src/xercesc/util/BinFileInputStream.cpp?rev=1662880&r1=1662879&r2=1662880&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.1/src/xercesc/util/BinFileInputStream.cpp (original)
+++ xerces/c/branches/xerces-3.1/src/xercesc/util/BinFileInputStream.cpp Sat Feb 28 01:55:31 2015
@@ -61,7 +61,16 @@ BinFileInputStream::BinFileInputStream(c
 BinFileInputStream::~BinFileInputStream()
 {
     if (getIsOpen())
-        XMLPlatformUtils::closeFile(fSource, fMemoryManager);
+    {
+        try
+        {
+            XMLPlatformUtils::closeFile(fSource, fMemoryManager);
+        }
+        catch (...)
+        {
+            // There is nothing we can do about it here.
+        }
+    }
 }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org