Socket: fix a potential double free