Skip to content

Fix memory leaks (reported by Coverity Scan)#7094

Open
stweil wants to merge 12 commits into
kitodo:mainfrom
stweil:fix_coverity_issues
Open

Fix memory leaks (reported by Coverity Scan)#7094
stweil wants to merge 12 commits into
kitodo:mainfrom
stweil:fix_coverity_issues

Conversation

@stweil

@stweil stweil commented Jun 24, 2026

Copy link
Copy Markdown
Member

This pull request fixes all memory leaks which were reported by Coverity Scan.

stweil added 12 commits June 24, 2026 07:27
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>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · -4 duplication

Metric Results
Complexity 0
Duplication -4

View in Codacy

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.

@solth

solth commented Jun 24, 2026

Copy link
Copy Markdown
Member

Please always provide at least a short description as I will not accept pull requests without any description in the future.

@stweil

stweil commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

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 git bisect, for example.

@stweil

stweil commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

Please always provide at least a short description as I will not accept pull requests without any description in the future.

Relevant discussion and documentation:

@solth

solth commented Jun 24, 2026

Copy link
Copy Markdown
Member

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 Files.newOutputStream in try-with-resources in MetsKitodoValidatorTest, MetsKitodoWrapperTest and several other files in this pull request.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants