os-ospp-dsp / threads-synchronization-deadlock

Assignments about threads, synchronization and deadlock
0 stars 3 forks source link

Missing free in psem_destroy? #3

Open kamar535 opened 1 year ago

kamar535 commented 1 year ago

Should there be a free(sem) in https://github.com/os-ospp-dsp/threads-synchronization-deadlock/blob/main/mandatory/psem/linux_semaphores.c or does sem_destroy take care of this?

kamar535 commented 1 year ago

I wrongly (stupidly) assumed that sem_destroy would do free on the memory to which a pointer was passed to sem_init. Calling sem_destroy only "destroys" the internals of the semaphore but since I used malloc to allocate that memory I must use free to de-allocate.