echo_srv: Do not close bogus file descriptors
authorAndreas Schneider <asn@samba.org>
Fri, 28 Sep 2018 10:55:49 +0000 (12:55 +0200)
committerAndreas Schneider <asn@samba.org>
Tue, 23 Oct 2018 13:39:19 +0000 (15:39 +0200)
==1564== Warning: invalid file descriptor 1048564 in syscall close()
==1564==    at 0x4D18534: close (in /lib64/libc-2.27.so)
==1564==    by 0x4046A74: libc_close (socket_wrapper.c:760)
==1564==    by 0x405105C: swrap_close (socket_wrapper.c:5933)
==1564==    by 0x40511F5: close (socket_wrapper.c:5979)
==1564==    by 0x401679: become_daemon (echo_srv.c:202)
==1564==    by 0x402D44: main (echo_srv.c:896)
==1563==

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
tests/echo_srv.c

index b97c3753520f8ffb369369f9157d03aa4ce7e47c..d2f3967b1d41c69de9fe0fed2af92d2b83d2c7b6 100644 (file)
@@ -198,11 +198,9 @@ static int become_daemon(void)
         return ret;
     }
 
-    for (fd = getdtablesize(); fd >= 0; --fd) {
-        close(fd);
-    }
-
     for (i = 0; i < 3; i++) {
+        close(i);
+
         fd = open("/dev/null", O_RDWR, 0);
         if (fd < 0) {
             fd = open("/dev/null", O_WRONLY, 0);