diff options
author | GDR! <gdr@gdr.name> | 2015-07-07 19:07:30 +0200 |
---|---|---|
committer | GDR! <gdr@gdr.name> | 2015-07-07 19:07:30 +0200 |
commit | 568238b53927804119dcc892919654deb961c4eb (patch) | |
tree | 109fbf3ac86b54f5ff24f8dd39d43a1beb5476e3 /client.c | |
parent | 71f6953feb4b8bd9914f04210fb23d5558c92960 (diff) |
CID 122515 (#1 of 1): Resource leak (RESOURCE_LEAK)6. leaked_storage:
Variable res going out of scope leaks the storage it points to.
Diffstat (limited to 'client.c')
-rw-r--r-- | client.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -42,6 +42,7 @@ int local_bind() | |||
42 | char port[6]; | 42 | char port[6]; |
43 | int yes = 1; | 43 | int yes = 1; |
44 | int flags; | 44 | int flags; |
45 | int gai_status; | ||
45 | 46 | ||
46 | snprintf(port, 6, "%d", local_port); | 47 | snprintf(port, 6, "%d", local_port); |
47 | 48 | ||
@@ -50,12 +51,18 @@ int local_bind() | |||
50 | hints.ai_socktype = SOCK_STREAM; | 51 | hints.ai_socktype = SOCK_STREAM; |
51 | hints.ai_flags = AI_PASSIVE; // fill in my IP for me | 52 | hints.ai_flags = AI_PASSIVE; // fill in my IP for me |
52 | 53 | ||
53 | getaddrinfo(NULL, port, &hints, &res); | 54 | gai_status = getaddrinfo(NULL, port, &hints, &res); |
55 | if(gai_status != 0) | ||
56 | { | ||
57 | log_printf(L_ERROR, "getaddrinfo: %s\n", gai_strerror(gai_status)); | ||
58 | exit(1); | ||
59 | } | ||
54 | 60 | ||
55 | bind_sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); | 61 | bind_sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); |
56 | if(bind_sockfd < 0) | 62 | if(bind_sockfd < 0) |
57 | { | 63 | { |
58 | log_printf(L_ERROR, "Could not create a socket for local listening: %s\n", strerror(errno)); | 64 | log_printf(L_ERROR, "Could not create a socket for local listening: %s\n", strerror(errno)); |
65 | freeaddrinfo(res); | ||
59 | exit(1); | 66 | exit(1); |
60 | } | 67 | } |
61 | 68 | ||
@@ -71,10 +78,13 @@ int local_bind() | |||
71 | if(bind(bind_sockfd, res->ai_addr, res->ai_addrlen) < 0) | 78 | if(bind(bind_sockfd, res->ai_addr, res->ai_addrlen) < 0) |
72 | { | 79 | { |
73 | log_printf(L_ERROR, "Bind to port %d failed: %s\n", local_port, strerror(errno)); | 80 | log_printf(L_ERROR, "Bind to port %d failed: %s\n", local_port, strerror(errno)); |
81 | freeaddrinfo(res); | ||
74 | close(bind_sockfd); | 82 | close(bind_sockfd); |
75 | exit(1); | 83 | exit(1); |
76 | } | 84 | } |
77 | 85 | ||
86 | freeaddrinfo(res); | ||
87 | |||
78 | if(listen(bind_sockfd, 1) < 0) | 88 | if(listen(bind_sockfd, 1) < 0) |
79 | { | 89 | { |
80 | log_printf(L_ERROR, "Listening on port %d failed: %s\n", local_port, strerror(errno)); | 90 | log_printf(L_ERROR, "Listening on port %d failed: %s\n", local_port, strerror(errno)); |