From fed78d17f39aff6bf639e9e7a05bead8ec431554 Mon Sep 17 00:00:00 2001 From: mamil Date: Tue, 13 Oct 2020 11:42:44 +0300 Subject: [PATCH] fix socket leak --- webbench-1.5/socket.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/webbench-1.5/socket.c b/webbench-1.5/socket.c index b7af54a..16e38b9 100644 --- a/webbench-1.5/socket.c +++ b/webbench-1.5/socket.c @@ -9,10 +9,10 @@ SCCS ID: @(#)socket.c 1.5 4/1/94 programmer: Virginia Tech Computing Center compiler: DEC RISC C compiler (Ultrix 4.1) - environment: DEC Ultrix 4.3 + environment: DEC Ultrix 4.3 description: UNIX sockets code. ***********************************************************************/ - + #include #include #include @@ -32,7 +32,7 @@ int Socket(const char *host, int clientPort) unsigned long inaddr; struct sockaddr_in ad; struct hostent *hp; - + memset(&ad, 0, sizeof(ad)); ad.sin_family = AF_INET; @@ -47,12 +47,15 @@ int Socket(const char *host, int clientPort) memcpy(&ad.sin_addr, hp->h_addr, hp->h_length); } ad.sin_port = htons(clientPort); - + sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) return sock; if (connect(sock, (struct sockaddr *)&ad, sizeof(ad)) < 0) + { + close(sock); return -1; + } return sock; }