More fixes of some Coverity issues.

Signed-off-by: Ruben Moral <Ruben.Moral@digi.com>
Fixed an issue related to a lock when closing the serial port.

Signed-off-by: Ruben Moral <Ruben.Moral@digi.com>