Skip to content

Commit c2bb580

Browse files
mernsttheit
authored andcommitted
Ensure FileOutputStream is closed in CommonsCompressAction.execute() (apache#1415)
1 parent a1b7ced commit c2bb580

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/CommonsCompressAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public static boolean execute(final String name, final File source, final File d
104104
}
105105
LOGGER.debug("Starting {} compression of {}", name, source.getPath() );
106106
try (final FileInputStream input = new FileInputStream(source);
107+
final FileOutputStream fileOutput = new FileOutputStream(destination);
107108
final BufferedOutputStream output = new BufferedOutputStream(
108-
new CompressorStreamFactory().createCompressorOutputStream(name, new FileOutputStream(
109-
destination)))) {
109+
new CompressorStreamFactory().createCompressorOutputStream(name, fileOutput))) {
110110
IOUtils.copy(input, output, BUF_SIZE);
111111
LOGGER.debug("Finished {} compression of {}", name, source.getPath() );
112112
} catch (final CompressorException e) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xmlns="http://logging.apache.org/log4j/changelog"
20+
xsi:schemaLocation="http://logging.apache.org/log4j/changelog https://logging.apache.org/log4j/changelog-0.1.1.xsd"
21+
type="fixed">
22+
<author id="mernst"/>
23+
<author id="vy"/>
24+
<description format="asciidoc">
25+
Ensure `FileOutputStream` is closed in `CommonsCompressAction.execute()`
26+
</description>
27+
</entry>

0 commit comments

Comments
 (0)