If the accept() on the listen_fd fails, we don't have a valid
file descriptor but tried to close it anyway. Even worse, the
old code dereferenced and then freed the "sc" pointer which
isn't inititialized at that point.
if (!FD_ISSET(listen_fd, rfds))
return;
ret = para_accept(listen_fd, NULL, 0);
- if (ret < 0)
- goto err_out;
+ if (ret < 0) {
+ PARA_ERROR_LOG("%s\n", para_strerror(-ret));
+ return;
+ }
sc = para_calloc(sizeof(*sc));
sc->fd = ret;
sc->name = make_message("%s", remote_name(sc->fd));
return;
err_out:
PARA_WARNING_LOG("%s\n", para_strerror(-ret));
- if (sc->fd > 0)
- close(sc->fd);
+ close(sc->fd);
free(sc);
}