Skip to content

macOS: dispatch_semaphore_t leak in semabin destructor #124

Description

@zhengying

semabin::~semabin() on macOS calls release() but never dispatch_release(), so every watch instance leaks a dispatch_semaphore_t.

Current code (detail/wtr/watcher/semabin.hpp):

inline ~semabin() noexcept { this->release(); }

release() only signals the semaphore to wake up waiters. It does not balance the +1 retain from dispatch_semaphore_create(0).

Fix:

inline ~semabin() noexcept
{
    this->release();
    dispatch_release(this->sem);
}

The project is built as pure C++ (no .mm files, no ARC), so dispatch_release is required here. No #if guards needed for the current build setup.

Impact: Any program that creates and destroys multiple watch objects on macOS will slowly leak GCD semaphores.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions