I am trying to track down an issue in the ESP-IDF; my version appears to be using FreeRTOS v10.2.1. In several places when cleaning up some obj, the code uses an idiom like this:
Its hard to say if the code is correct or not without knowing what the semaphore is used for, but assuming the semaphore is not being used after it is deleted then I think it would only make a difference for mutex type semaphores. If the semaphore is a mutex then taking the semaphore could result in priority inheritance if a higher priority task attempted to take the same semaphore before it was deleted. Deleting the semaphore would mean the inherited priority would never be returned to back to its original priority. That would be a rare corner case though, and only be possible if something else was trying to take the semaphore at the same time - which would be dangerous even without priority inheritance if the semaphore is deleted immediately after.
Looking at the code I suspect it is taking the semaphore before deleting it to ensure the semaphore is not held by any other task before it gets deleted.