Skip to content

Fix leaked DIR* handle in generatedEntryIndex()#253

Open
datacarismo wants to merge 1 commit into
Slackadays:mainfrom
datacarismo:fix/opendir-leak
Open

Fix leaked DIR* handle in generatedEntryIndex()#253
datacarismo wants to merge 1 commit into
Slackadays:mainfrom
datacarismo:fix/opendir-leak

Conversation

@datacarismo

Copy link
Copy Markdown

Summary

Fixes a file descriptor leak in Clipboard::generatedEntryIndex() where the DIR* returned by opendir() was never passed to closedir().

Changes

  • Added null check for opendir() return value with early return
  • Wrapped dirptr in std::unique_ptr<DIR, decltype(&closedir)> for RAII cleanup
  • Added #include <memory>

Impact

This leak occurred on every clipboard operation that called generatedEntryIndex() (essentially every invocation on Unix-like systems). Over time, repeated use could exhaust available file descriptors.

Wrap opendir() result in std::unique_ptr with closedir deleter to
ensure the directory handle is always released, preventing a file
descriptor leak on every call. Also add a null check for the case
where opendir() fails.
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.

1 participant