Skip to content

Commit f371b98

Browse files
author
Tom Schaible
committed
[JENKINS-53485] fix to a file leak introduced in the libraryResource pipeline step
1 parent fb77443 commit f371b98

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/java/org/jenkinsci/plugins/workflow/libs/LibraryAdder.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import hudson.model.TaskListener;
3434
import java.io.File;
3535
import java.io.IOException;
36+
import java.io.InputStream;
3637
import java.net.URL;
3738
import java.util.ArrayList;
3839
import java.util.Base64;
@@ -214,10 +215,12 @@ static List<URL> retrieve(@Nonnull String name, @Nonnull String version, @Nonnul
214215
}
215216

216217
private static String readResource(FilePath file, @CheckForNull String encoding) throws IOException, InterruptedException {
217-
if ("Base64".equals(encoding)) {
218-
return Base64.getEncoder().encodeToString(IOUtils.toByteArray(file.read()));
219-
} else {
220-
return IOUtils.toString(file.read(), encoding); // The platform default is used if encoding is null.
218+
try (InputStream in = file.read()) {
219+
if ("Base64".equals(encoding)) {
220+
return Base64.getEncoder().encodeToString(IOUtils.toByteArray(in));
221+
} else {
222+
return IOUtils.toString(in, encoding); // The platform default is used if encoding is null.
223+
}
221224
}
222225
}
223226

0 commit comments

Comments
 (0)