Skip to content

[BUG]: Windows CloseHandle called twice in cthreads_thread_join #10

Description

@TCWORLD

CThreads commit

c225bf9

Description

When joining threads on Windows, the process crashes in the final call to cthreads_thread_detach with exception that the thread handle has already been closed.

Looking at the code, it seems a call to CloseHandle was recently added to cthreads_thread_join:

CThreads/cthreads.c

Lines 126 to 130 in c225bf9

CloseHandle(handle);
if (code) *(void **)code = (void *)(uintptr_t)exit_code;
return cthreads_thread_detach(thread);

However on the final return call through cthreads_thread_detach, the CloseHandle function is called a second time.

Removing line 126 above fixes the problem.

Steps to reproduce

  1. Compile for windows.
  2. Create a thread using cthreads_thread_create with default attributes.
  3. Have the thread function simply return
  4. Call cthreads_thread_join from the main thread.
  5. Exception occurs.

Example code

No response

Confirmations

  • My environment meets the minimum requirements.
  • I have verified that this is not a duplicate issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnot confirmedThis issue or pull request is not confirmed to be done.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions