mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2026-04-25 05:16:00 +03:00
[PR #2790] [MERGED] Use scope_guard for directory handles to prevent leaks #2791
Labels
No labels
bug
bug
dataloss
duplicate
enhancement
feature request
help wanted
invalid
need info
performance
pull-request
question
question
testing
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/s3fs-fuse#2791
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/s3fs-fuse/s3fs-fuse/pull/2790
Author: @CarstenGrohmann
Created: 1/23/2026
Status: ✅ Merged
Merged: 1/24/2026
Merged by: @ggtakec
Base:
master← Head:scope_guard_for_directory_handles📝 Commits (1)
538e86aUse scope_guard for directory handles to prevent leaks📊 Changes
3 files changed (+5 additions, -9 deletions)
View changed files
📝
src/fdcache.cpp(+2 -3)📝
src/s3fs.cpp(+2 -2)📝
src/s3fs_util.cpp(+1 -4)📄 Description
This PR replaces manual
closedir()calls with the existingscope_guardRAII pattern in directory-traversing functions. This ensures directory handles are properly closed even when exceptions occur.Problem:
The affected functions iterate over directories using
opendir()/readdir()/closedir(). They contain:std::stringoperations that can throwstd::bad_allocWhen an exception is thrown, execution bypasses the manual closedir() calls, causing directory handle leaks. In long-running processes with deep directory trees, this can eventually exhaust the file descriptor limit.
Solution:
Use the existing scope_guard class (defined in
s3fs_util.h) to ensureclosedir()is called when the scope exits, regardless of how it exits:Hint:
The code in
s3fs.cppwas correct and was only modified for consistency with the rest of the codebase.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.