Skip to content

Commit fed78d1

Browse files
committed
fix socket leak
1 parent 0d0df89 commit fed78d1

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

webbench-1.5/socket.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
SCCS ID: @(#)socket.c 1.5 4/1/94
1010
programmer: Virginia Tech Computing Center
1111
compiler: DEC RISC C compiler (Ultrix 4.1)
12-
environment: DEC Ultrix 4.3
12+
environment: DEC Ultrix 4.3
1313
description: UNIX sockets code.
1414
***********************************************************************/
15-
15+
1616
#include <sys/types.h>
1717
#include <sys/socket.h>
1818
#include <fcntl.h>
@@ -32,7 +32,7 @@ int Socket(const char *host, int clientPort)
3232
unsigned long inaddr;
3333
struct sockaddr_in ad;
3434
struct hostent *hp;
35-
35+
3636
memset(&ad, 0, sizeof(ad));
3737
ad.sin_family = AF_INET;
3838

@@ -47,12 +47,15 @@ int Socket(const char *host, int clientPort)
4747
memcpy(&ad.sin_addr, hp->h_addr, hp->h_length);
4848
}
4949
ad.sin_port = htons(clientPort);
50-
50+
5151
sock = socket(AF_INET, SOCK_STREAM, 0);
5252
if (sock < 0)
5353
return sock;
5454
if (connect(sock, (struct sockaddr *)&ad, sizeof(ad)) < 0)
55+
{
56+
close(sock);
5557
return -1;
58+
}
5659
return sock;
5760
}
5861

0 commit comments

Comments
 (0)