Skip to content

[TECHNICAL] Resource leak in CopyAndUploadContentUrisTask #4806

Open
dataCenter430 wants to merge 2 commits intoowncloud:masterfrom
dataCenter430:technical/copy-and-upload-content-uris-resource-leak
Open

[TECHNICAL] Resource leak in CopyAndUploadContentUrisTask #4806
dataCenter430 wants to merge 2 commits intoowncloud:masterfrom
dataCenter430:technical/copy-and-upload-content-uris-resource-leak

Conversation

@dataCenter430
Copy link
Contributor

…UrisTask

Related Issues

Fixes #4797

Summary

Fixes a resource leak in CopyAndUploadContentUrisTask reported in #4797.

Problem

In the loop over URIs (lines 147–182), inputStream and outputStream were reassigned every iteration but never closed inside the loop. Only the last iteration’s streams were closed in the outer finally block, so all previous streams were leaked (file descriptors and memory).

Solution

  • Use try-with-resources inside the loop so each iteration opens and closes its own InputStream and FileOutputStream.
  • Remove the outer inputStream/outputStream variables and the stream-closing logic from the outer finally block.

Each URI’s streams are now closed at the end of that iteration (normal or exceptional), so no streams are leaked.

  • Add changelog files for the fixed issues in folder changelog/unreleased. More info here

@dataCenter430 dataCenter430 force-pushed the technical/copy-and-upload-content-uris-resource-leak branch from d1b1561 to bcfe14e Compare March 16, 2026 05:14
@dataCenter430
Copy link
Contributor Author

Hi, @joragua
Sorry for the late PR.
I really appreciate your review with this.
Thank you

@dataCenter430 dataCenter430 changed the title fix: Resource leak in CopyAndUploadContentUrisTask [TECHNICAL] Resource leak in CopyAndUploadContentUrisTask Mar 16, 2026
@joragua
Copy link
Collaborator

joragua commented Mar 16, 2026

Thanks for your contribution @dataCenter430! 💯 I'll check this PR as soon as possible

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.

[TECHNICAL] Resource leak in CopyAndUploadContentUrisTask.java

2 participants