Question: In the process-based server in Figure 12.5, we observed that there is no memory leak and the code remains correct even when line 33 is
In the process-based server in Figure 12.5, we observed that there is no memory leak and the code remains correct even when line 33 is deleted. In the threads based server in Figure 12.14, are there any chances of memory leak if lines 31 or 32 are deleted. Why?
Figure 12.5

Figure 12.14

1 #include "csapp.h" 2 void echo(int connfd); 3 4 5 6 7 8 9 10 11 234 13 12 { 14 15 16 17 18 19 void sigchld_handler (int sig) { 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 } while (waitpid (-1, 0, WNOHANG) > 0) int main(int argc, char **argv) } ; return; int listenfd, connfd; socklen_t clientlen; struct sockaddr_storage clientaddr; if (argc != 2) { fprintf(stderr, "usage: %s ", argv[0]); exit(0); } Signal (SIGCHLD, listenfd = sigchld_handler); Open listenfd (argv[1]); while (1) { clientlen = sizeof (struct sockaddr_storage); } connfd = Accept (listenfd, (SA) &clientaddr, &clientlen); if (Fork() == 0) { Close (listenfd); /* Child closes its listening socket */ echo (connfd); /* Child services client */ Close (connfd); /* Child closes connection with client */ exit(0); /* Child exits */ } Close (connfd); /* Parent closes connected socket (important!) */
Step by Step Solution
3.56 Rating (180 Votes )
There are 3 Steps involved in it
Yes there are chances of memory leak if lines 31 or 32 are deleted from Figure 1214 Since the th... View full answer
Get step-by-step solutions from verified subject matter experts
