From 88da51d91b1f6f29b1d965e482b31b96f3d05318 Mon Sep 17 00:00:00 2001 From: Kaneki Date: Sun, 22 Mar 2026 11:19:50 +0800 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + .../src/main/java/ai/openclaw/app/node/CameraHandler.kt | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55f1151e89a..2064b2ac79d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -559,6 +559,7 @@ Docs: https://docs.openclaw.ai - macOS/remote gateway: stop PortGuardian from killing Docker Desktop and other external listeners on the gateway port in remote mode, so containerized and tunneled gateway setups no longer lose their port-forward owner on app startup. (#6755) Thanks @teslamint. - Feishu/streaming recovery: clear stale `streamingStartPromise` when card creation fails (HTTP 400) so subsequent messages can retry streaming instead of silently dropping all future replies. Fixes #43322. - Exec/env sandbox: block JVM agent injection (`JAVA_TOOL_OPTIONS`, `_JAVA_OPTIONS`, `JDK_JAVA_OPTIONS`), Python breakpoint hijack (`PYTHONBREAKPOINT`), and .NET startup hooks (`DOTNET_STARTUP_HOOKS`) from the host exec environment. (#49025) +- Android/camera clip cleanup: delete temporary clip files even when `readBytes()` fails so failed clip captures do not leak cache storage. (#41890) Thanks @Kaneki-x. ### Security diff --git a/apps/android/app/src/main/java/ai/openclaw/app/node/CameraHandler.kt b/apps/android/app/src/main/java/ai/openclaw/app/node/CameraHandler.kt index 3e7881f2625..784c14d6669 100644 --- a/apps/android/app/src/main/java/ai/openclaw/app/node/CameraHandler.kt +++ b/apps/android/app/src/main/java/ai/openclaw/app/node/CameraHandler.kt @@ -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")