sock: add a missing lock/unlock
+ code cleanup