In acquire_spi, making condition of acquiring the releasing lock aligned.
Fixes #2939
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2941
-- Commit Summary --
* Fix a possible deadlock bug due to unreleased lock
-- File Changes --
M src/modules/ims_ipsec_pcscf/spi_gen.c (6)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2941.patch https://github.com/kamailio/kamailio/pull/2941.diff
Thanks for the pull request. I am not 100% sure if this approach is the right one. * in line 83 the lock is allocated, sure * the while loop basically has two exit conditions * there are no free SPIs - first unlock, line 109 * a free SPI was found - second unlock, line 121
Your pull request changes this logic to unconditionally unlock, and then do a second unlock again, if I am not wrong?
My observation is that because the lock is acquired first (Line83) so the lock should be safely released before returning. https://github.com/kamailio/kamailio/blob/1ddc27f199061025a6a43da3e8a1388fca...
I've missed the missing braces around the if condition, right. Let me have another look at the logic later today.
There is an build error reported from the auto-build, maybe you can have a look.
Closed #2941.
@henningw Thank you for your time. The code can always ensure that the lock is released at line 109 before returning.