removed malloc, since the semaphore should be initialized before. Also fixed the destruction of the semaphore