Skip to content

Close FileOutputStream in MonitorActivity.initMonitor() - #474

Open
munzzyy wants to merge 1 commit into
guardianproject:masterfrom
munzzyy:fix-monitoractivity-fd-leak
Open

Close FileOutputStream in MonitorActivity.initMonitor()#474
munzzyy wants to merge 1 commit into
guardianproject:masterfrom
munzzyy:fix-monitoractivity-fd-leak

Conversation

@munzzyy

@munzzyy munzzyy commented Sep 3, 2026

Copy link
Copy Markdown

Fixes #469.

initMonitor() opens a FileOutputStream to write the .nomedia marker file but never closes it:

new FileOutputStream(new File(fileImageDir, ".nomedia")).write(0);

This runs every time monitoring starts (or restarts), so the descriptor leaks on every cycle. Swapped it for try-with-resources so the stream always gets closed, even if write() throws.

Small, single-purpose change, no behavior difference otherwise.

The .nomedia file is written with a raw FileOutputStream that's never
closed, leaking a file descriptor every time monitoring is started or
restarted. Switched to try-with-resources so the stream always closes,
including when write() throws.

Fixes guardianproject#469
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.

[Resource Leak] FileOutputStream not closed in MonitorActivity.initMonitor()

1 participant