Make sure we close all open files.

This commit is contained in:
Martin Baulig
2000-02-14 14:25:34 +00:00
parent c92bf0f9a9
commit 00a32c887c
4 changed files with 11 additions and 4 deletions

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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)) {

View File

@@ -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;
}