From a40e2b857e0079cbadcb7572dfe3ce04fecbece4 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Wed, 4 Feb 2026 13:54:24 +0900 Subject: [PATCH] fix(git): fix resource leak in countCommits on exception Replace RETURN_IF_EXCEPTION with explicit cleanup that frees the git_revwalk before returning when toWTFString throws an exception. Co-Authored-By: Claude Opus 4.5 --- src/bun.js/bindings/git/JSGit.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bun.js/bindings/git/JSGit.cpp b/src/bun.js/bindings/git/JSGit.cpp index 62801836c4..e2ab1bfe30 100644 --- a/src/bun.js/bindings/git/JSGit.cpp +++ b/src/bun.js/bindings/git/JSGit.cpp @@ -792,7 +792,10 @@ JSC_DEFINE_HOST_FUNCTION(jsGitRepositoryCountCommits, (JSC::JSGlobalObject * lex } WTF::String rangeString = rangeValue.toWTFString(lexicalGlobalObject); - RETURN_IF_EXCEPTION(scope, {}); + if (scope.exception()) [[unlikely]] { + git_revwalk_free(walk); + return JSC::JSValue::encode(JSC::jsUndefined()); + } WTF::CString rangeCString = rangeString.utf8(); error = git_revwalk_push_range(walk, rangeCString.data());