[logback-dev] [JIRA] Updates for LOGBACK-1755: potential resource leak bug in test code
logback developers list
logback-dev at qos.ch
Fri Jul 7 13:07:00 CEST 2023
logback / LOGBACK-1755 [Open]
potential resource leak bug in test code
==============================
Here's what changed in this issue in the last few minutes.
This issue has been created
This issue is now assigned to you.
View or comment on issue using this link
https://jira.qos.ch/browse/LOGBACK-1755
==============================
Issue created
------------------------------
Alfusainey Jallow created this issue on 07/Jul/23 12:55
Summary: potential resource leak bug in test code
Issue Type: Bug
Assignee: Logback dev list
Components: logback-core
Created: 07/Jul/23 12:55
Priority: Minor
Reporter: Alfusainey Jallow
Description:
There is a potential resource leak bug in the implementation of the CompressTest{{{}#copy(){}}} method.
This method copies the contents of one file to another. However, the input and output streams will not be closed if an exception is thrown during the {{write}} operation. One solution is to use try-with-resources so that it is guaranteed that the streams will be close in the event an exception is thrown.
{code:java}
public static void copy(File src, File dst) throws IOException {
try (InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst)) {
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
}
}
{code}
The priority for this issue is minor since it affects only test code. Can someone kindly confirm if this is an issue?
*Context*
We came across this issue while investigating open-source projects to see if they contain code that is similar to (or reused from) Stack Overflow and whether the code on Stack Overflow underwent any bug or security fixes. We found that the code in the {{{}CompressTest{}}}{{{}{}}}{{{}#copy(){}}} method is somewhat similar to the one in the first version of [this answer|https://stackoverflow.com/revisions/9293885/1]. The issue was subsequently fixed in the [second version|https://stackoverflow.com/revisions/9293885/2], however, the fix is not reflected in this method.
==============================
This message was sent by Atlassian Jira (v9.6.0#960000-sha1:a3ee8af)
More information about the logback-dev
mailing list