Fixed a memory cleanup issue with shared semaphores

Signed-off-by: Shahbaz Youssefi <ShabbyX@gmail.com>