fix potential resource leak

It fixes a potential leak on sock if a integer overflow occurs