Android: fix temp file leak in CameraHandler.handleClip (#41890)

* Android: fix temp file leak in CameraHandler.handleClip

When readBytes() throws (IOException, OOM, etc.), the recorded clip
file was never deleted because delete() only ran on the success path.

Move file.delete() into a finally block so the temp file is cleaned up
regardless of whether readBytes() succeeds or fails.

Made-with: Cursor

* fix: Android camera clip cleanup (#41890) (thanks @Kaneki-x)

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
This commit is contained in:
Kaneki
2026-03-22 11:19:50 +08:00
committed by GitHub
parent 506861efd0
commit 88da51d91b
2 changed files with 6 additions and 3 deletions

View File

@@ -134,9 +134,11 @@ class CameraHandler(
}
val bytes = withContext(Dispatchers.IO) {
val b = filePayload.file.readBytes()
filePayload.file.delete()
b
try {
filePayload.file.readBytes()
} finally {
filePayload.file.delete()
}
}
val base64 = android.util.Base64.encodeToString(bytes, android.util.Base64.NO_WRAP)
clipLog("returning base64 payload")