Author: dkulp Date: Fri May 25 15:46:14 2012 New Revision: 1342698 URL: http://svn.apache.org/viewvc?rev=1342698&view=rev Log: Merged revisions 1342690 via svn merge from https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes
........ r1342690 | dkulp | 2012-05-25 11:41:43 -0400 (Fri, 25 May 2012) | 10 lines Merged revisions 1342687 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/trunk ........ r1342687 | dkulp | 2012-05-25 11:38:54 -0400 (Fri, 25 May 2012) | 3 lines [CXF-4342] Put some locking around tempFile deletion and make sure any issues in creating the tempfile result in it getting cleaned up. ........ ........ Modified: cxf/branches/2.4.x-fixes/ (props changed) cxf/branches/2.4.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.4.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?rev=1342698&r1=1342697&r2=1342698&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java (original) +++ cxf/branches/2.4.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java Fri May 25 15:46:14 2012 @@ -245,8 +245,7 @@ public class CachedOutputStream extends IOUtils.copyAndCloseInput(fin, out); } streamList.remove(currentStream); - tempFile.delete(); - tempFile = null; + deleteTempFile(); inmem = true; } } @@ -444,7 +443,10 @@ public class CachedOutputStream extends //Could be IOException or SecurityException or other issues. //Don't care what, just keep it in memory. tempFileFailed = true; - tempFile = null; + if (currentStream != bout) { + currentStream.close(); + } + deleteTempFile(); inmem = true; currentStream = bout; } @@ -482,6 +484,13 @@ public class CachedOutputStream extends } } + private synchronized void deleteTempFile() { + if (tempFile != null) { + File file = tempFile; + tempFile = null; + FileUtils.delete(file); + } + } private void maybeDeleteTempFile(Object stream) { streamList.remove(stream); if (!inmem && tempFile != null && streamList.isEmpty() && allowDeleteOfFile) { @@ -493,8 +502,7 @@ public class CachedOutputStream extends //ignore } } - tempFile.delete(); - tempFile = null; + deleteTempFile(); currentStream = new LoadingByteArrayOutputStream(1024); inmem = true; }
