I feel that "error case free" should be done in do_accept() rather than caller. After strdup(), there are 2 "return (0)". How about adding "free(*host)" before these 2 "return (0)" ? I worried that error return occurs before strdup() in do_accept().
On Sun, Aug 19, 2018 at 10:40:55AM +0200, Theo Buehler wrote: > do_accept() may strdup() the host name and store it in `name', so we > need to free it before exiting. Perhaps a refactor might be more > appropriate, but I'm not sure I want to touch this mess. > > Index: s_socket.c > =================================================================== > RCS file: /var/cvs/src/usr.bin/openssl/s_socket.c,v > retrieving revision 1.9 > diff -u -p -r1.9 s_socket.c > --- s_socket.c 7 Feb 2018 05:47:55 -0000 1.9 > +++ s_socket.c 19 Aug 2018 07:13:49 -0000 > @@ -151,6 +151,7 @@ do_server(int port, int type, int *ret, > if (do_accept(accept_socket, &sock, &name) == 0) { > shutdown(accept_socket, SHUT_RD); > close(accept_socket); > + free(name); > return (0); > } > } else