Free temporary variable in error path

Fix Coverity CID 56890

Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
Re-start loop if select fails

Fix Coverity error CID 56882

Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
Prevent tmpbuf from overrunning

Fix Coverity error CID 56886.

Signed-off-by: Gregor Jasny <gjasny@googlemail.com>