Fix releasing semaphore stored in free'd memory