Opened 11 years ago

Closed 11 years ago

#5859 closed Bugs (fixed)

win32 shared_mutex constructor leaks on exceptions

Reported by: phrosty@… Owned by: viboes
Milestone: Boost 1.49.0 Component: thread
Version: Boost 1.47.0 Severity: Problem
Keywords: shared_mutex Cc: viboes

Description

shared_mutex's contructor contains three calls to create_anonymous_semaphore(), each of which can throw. If one of these throws, the unprotected handles of the previous ones will leak.

Change History (5)

comment:1 by viboes, 11 years ago

Cc: viboes added
Owner: changed from Anthony Williams to viboes
Status: newassigned

Thanks for this report. I will try to solve it soon.

comment:2 by viboes, 11 years ago

In order to avoid a chained try-catch a no_throw create_anonymous_semaphore_nothrow function can be used like in

            if (!semaphores[exclusive_sem])
            {
              detail::win32::release_semaphore(semaphores[unlock_sem],LONG_MAX);
              boost::throw_exception(thread_resource_error());
            }
            upgrade_sem=detail::win32::create_anonymous_semaphore_nothrow(0,LONG_MAX);
            if (!upgrade_sem)
            {
              detail::win32::release_semaphore(semaphores[unlock_sem],LONG_MAX);
              detail::win32::release_semaphore(semaphores[exclusive_sem],LONG_MAX);
              boost::throw_exception(thread_resource_error());
            }

While this is not too elegant it solves the issue. A RAI handle would be also appreciated.

comment:3 by viboes, 11 years ago

Milestone: To Be DeterminedBoost 1.49.0
Resolution: fixed
Status: assignedclosed

Committed in trunk At revision: [75806]

Last edited 10 years ago by viboes (previous) (diff)

comment:4 by viboes, 11 years ago

Resolution: fixed
Status: closedreopened

Let close the ticket when merged to release

comment:5 by viboes, 11 years ago

Resolution: fixed
Status: reopenedclosed

Committed in release at [76291]

Last edited 10 years ago by viboes (previous) (diff)
Note: See TracTickets for help on using tickets.