diff --git a/sysdeps/linux/glibtop_server.h b/sysdeps/linux/glibtop_server.h index 4889d2df..a8d3e083 100644 --- a/sysdeps/linux/glibtop_server.h +++ b/sysdeps/linux/glibtop_server.h @@ -71,10 +71,11 @@ proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid) if (fd < 0) return -1; len = read (fd, buffer, BUFSIZ-1); - if (len < 0) return -1; - close (fd); + if (len < 0) + return -1; + buffer [len] = '\0'; return 0; diff --git a/sysdeps/linux/netinfo.c b/sysdeps/linux/netinfo.c index 054439a9..e15e1319 100644 --- a/sysdeps/linux/netinfo.c +++ b/sysdeps/linux/netinfo.c @@ -237,7 +237,9 @@ _netinfo_ipv6 (glibtop *server, glibtop_netinfo *buf, buf->transport = GLIBTOP_TRANSPORT_IPV6; buf->flags |= (1L << GLIBTOP_NETINFO_TRANSPORT); - if ((f = fopen (_PATH_PROCNET_IFINET6, "r")) != NULL) { + f = fopen (_PATH_PROCNET_IFINET6, "r"); + + if (f != NULL) { while (fscanf (f, "%64s %02x %02x %02x %02x %20s\n", addr6, &if_idx, &plen, &scope, &dad_status, devname) != EOF) { diff --git a/sysdeps/linux/netload.c b/sysdeps/linux/netload.c index 2cd20d76..8300fe1f 100644 --- a/sysdeps/linux/netload.c +++ b/sysdeps/linux/netload.c @@ -222,7 +222,10 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf, } /* Should never happen. */ - if (fields < 2) return -1; + if (fields < 2) { + fclose (f); + return -1; + } fields--; while (fgets (buffer, BUFSIZ-1, f)) { diff --git a/sysdeps/linux/procargs.c b/sysdeps/linux/procargs.c index 86d4cfb1..9ff15cab 100644 --- a/sysdeps/linux/procargs.c +++ b/sysdeps/linux/procargs.c @@ -65,6 +65,7 @@ glibtop_get_proc_args_s (glibtop *server, glibtop_array *array, pid_t pid) while (1) { len = read (cmdline, buffer, BUFSIZ-1); if (len < 0) { + close (cmdline); glibtop_free_r (server, ptr); return NULL; }