Use try-finaly to make sure locks will be freed.

Signed-off-by: Tzachi Dar <tzachi.dar@gmail.com>