Fix memory leaks (reported by Coverity Scan)#7094
Conversation
Wrap Files.newOutputStream in try-with-resources to prevent CWE-404 resource leak when reverting testmetaOldFormat.xml. Signed-off-by: Stefan Weil <sw@weilnetz.de> Assisted-by: qwen3.6-36b (Alibaba)
…onWithStrictFileIdCheck() Wrap MockedStatic<KitodoConfig> in try-with-resources to prevent CWE-404 resource leak when mockedConfig goes out of scope. Signed-off-by: Stefan Weil <sw@weilnetz.de> Assisted-by: qwen3.6-36b (Alibaba)
Wrap Files.newOutputStream in try-with-resources to prevent CWE-404 resource leak when reverting testmetaOldFormat.xml. Signed-off-by: Stefan Weil <sw@weilnetz.de> Assisted-by: qwen3.6-36b (Alibaba)
Replace FileSystems.getDefault().getPath() with Paths.get() to avoid CWE-404 resource leak warning for the FileSystem returned by getDefault(). Both produce the same Path but Paths.get() avoids exposing the FileSystem resource. Signed-off-by: Stefan Weil <sw@weilnetz.de> Assisted-by: qwen3.6-36b (Alibaba)
Wrap Files.newOutputStream in try-with-resources to prevent CWE-404 resource leaks when reverting testmetaOldFormat.xml and testmetaUnsupportedFormat.xml. Signed-off-by: Stefan Weil <sw@weilnetz.de> Assisted-by: qwen3.6-36b (Alibaba)
Wrap Files.newOutputStream in try-with-resources to prevent CWE-404 resource leak when the stream is not properly closed after writing. Signed-off-by: Stefan Weil <sw@weilnetz.de> Assisted-by: qwen3.6-36b (Alibaba)
Replace FileSystems.getDefault().getPath() with Paths.get() to avoid CWE-404 resource leak warning for the FileSystem returned by getDefault(). Both produce the same Path but Paths.get() avoids exposing the FileSystem resource. Signed-off-by: Stefan Weil <sw@weilnetz.de> Assisted-by: qwen3.6-36b (Alibaba)
Wrap Files.newOutputStream in try-with-resources to prevent CWE-404 resource leak when the stream is not properly closed after writing. CID: 415123 Signed-off-by: Stefan Weil <sw@weilnetz.de> Assisted-by: qwen3.6-36b (Alibaba)
Capture MockedStatic<ParameterAPI> in a static field and close it in @afterall method to prevent CWE-404 resource leak when mockedStatic goes out of scope. CID: 415151 Signed-off-by: Stefan Weil <sw@weilnetz.de> Assisted-by: qwen3.6-36b (Alibaba)
Replace FileSystems.getDefault().getPath() with Paths.get() to avoid CWE-404 resource leak warnings for the FileSystem returned by getDefault() in loadBeans(), loadFrontendFilesIntoCore(), and loadModulesIntoClasspath(). Also remove now-unused FileSystems import. CID: 415123 Signed-off-by: Stefan Weil <sw@weilnetz.de> Assisted-by: qwen3.6-36b (Alibaba)
Wrap Files.newOutputStream in try-with-resources to prevent CWE-404 resource leak when the stream is not properly closed after writing. CID: 415068 Signed-off-by: Stefan Weil <sw@weilnetz.de> Assisted-by: qwen3.6-36b (Alibaba)
CID: 415099 Assisted-by: qwen3.6-36b (Alibaba) Signed-off-by: Stefan Weil <sw@weilnetz.de>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | -4 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
Please always provide at least a short description as I will not accept pull requests without any description in the future. |
|
Each commit has a lengthy description. If you prefer I can make a PR for each commit. But it is easier to either "create a merge commit" or to "rebase and merge" this PR. Then all detailled commit messages are preserved and will be part of the git history. Don't use "squash and merge" (unless in a few special cases) because it will mix unrelated changes into a single one. That's bad for |
Relevant discussion and documentation: |
|
I prefer having the information about the pull request available in the pull request description itself when reviewing it instead of heaving to click each and every commit of a pull request individually to see the information. In this repository we also use "squash and merge" to keep the commit history from becoming to cluttered, where possible, so please try to group similar changes accordingly. I accept this pull request as an exception but normally it is not necessary to make separate commits in one pull request for the same adjustment in different files (for example wrapping |
This pull request fixes all memory leaks which were reported by Coverity Scan.