Fix Semaphore leak, port #488 on master
Minor clean up