fix possible close of unrelated fd on error path

- infd var is uninitialised on error path in case where
  maxlen is less than 1