@cryptotaxi247 / netdata-1 / commits / c27acb5df

fixed issues identified by coverity

Costa Tsaousis (ktsaou) committed Jan 9, 2018 at 20:11 UTC c27acb5df8af6d64ec78d889e28e65c8a9d4fba7
3 files changed +28 -11
src/cgroup-network.c
+21 -5
@@ -86,6 +86,19 @@ struct iface *read_proc_net_dev(const char *prefix) {
86 return root;
87 }
88
89 +void free_iface(struct iface *iface) {
90 + freez((void *)iface->device);
91 + freez(iface);
92 +}
93 +
94 +void free_host_ifaces(struct iface *iface) {
95 + while(iface) {
96 + struct iface *t = iface->next;
97 + free_iface(iface);
98 + iface = t;
99 + }
100 +}
101 +
102 int iface_is_eligible(struct iface *iface) {
103 if(iface->iflink != iface->ifindex)
104 return 1;
@@ -330,7 +343,7 @@ void add_device(const char *host, const char *guest) {
343 if(f->host_device_hash == hash && strcmp(host, f->host_device) == 0) {
344
345 if(guest && !f->guest_device)
333 - f->guest_device = strdup(guest);
346 + f->guest_device = strdupz(guest);
347
348 return;
349 }
@@ -375,26 +388,26 @@ void detect_veth_interfaces(pid_t pid) {
388 if(!eligible_ifaces(host)) {
389 errno = 0;
390 error("there are no double-linked host interfaces available.");
378 - return;
391 + goto cleanup;
392 }
393
394 if(switch_namespace(prefix, pid)) {
395 errno = 0;
396 error("cannot switch to the namespace of pid %u", (unsigned int) pid);
384 - return;
397 + goto cleanup;
398 }
399
400 cgroup = read_proc_net_dev(NULL);
401 if(!cgroup) {
402 errno = 0;
403 error("cannot read cgroup interface list.");
391 - return;
404 + goto cleanup;
405 }
406
407 if(!eligible_ifaces(cgroup)) {
408 errno = 0;
409 error("there are not double-linked cgroup interfaces available.");
397 - return;
410 + goto cleanup;
411 }
412
413 for(h = host; h ; h = h->next) {
@@ -406,6 +419,9 @@ void detect_veth_interfaces(pid_t pid) {
419 }
420 }
421 }
422 +
423 +cleanup:
424 + free_host_ifaces(host);
425 }
426
427 // ----------------------------------------------------------------------------
src/socket.c
+2 -1
@@ -869,7 +869,8 @@ int accept4(int sock, struct sockaddr *addr, socklen_t *addrlen, int flags) {
869 #endif
870
871 if (flags) {
872 - errno = -EINVAL;
872 + close(fd);
873 + errno = EINVAL;
874 return -1;
875 }
876
src/web_client.c
+5 -5
@@ -81,14 +81,14 @@ static void web_client_update_acl_matches(struct web_client *w) {
81 w->acl |= WEB_CLIENT_ACL_BADGE;
82 }
83
84 -static void web_client_fix_socket(struct web_client *w) {
84 +static void web_client_initialize_connection(struct web_client *w) {
85 int flag = 1;
86 if(setsockopt(w->ifd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)) != 0)
87 - error("%llu: failed to enable TCP_NODELAY on socket fd %d.", w->id, w->ofd);
87 + error("%llu: failed to enable TCP_NODELAY on socket fd %d.", w->id, w->ifd);
88
89 flag = 1;
90 if(setsockopt(w->ifd, SOL_SOCKET, SO_KEEPALIVE, (char *) &flag, sizeof(int)) != 0)
91 - error("%llu: Cannot set SO_KEEPALIVE on socket fd %d.", w->id, w->ifd);
91 + error("%llu: failed to enable SO_KEEPALIVE on socket fd %d.", w->id, w->ifd);
92
93 web_client_update_acl_matches(w);
94
@@ -115,7 +115,7 @@ struct web_client *web_client_create_on_fd(int fd, const char *client_ip, const
115 if(unlikely(!*w->client_ip)) strcpy(w->client_ip, "-");
116 if(unlikely(!*w->client_port)) strcpy(w->client_port, "-");
117
118 - web_client_fix_socket(w);
118 + web_client_initialize_connection(w);
119 return(w);
120 }
121
@@ -144,7 +144,7 @@ struct web_client *web_client_create_on_listenfd(int listener) {
144 return NULL;
145 }
146
147 - web_client_fix_socket(w);
147 + web_client_initialize_connection(w);
148 return(w);
149 }
150