diff options
author | Martin Baulig <martin@src.gnome.org> | 2000-02-14 14:34:33 +0000 |
---|---|---|
committer | Martin Baulig <martin@src.gnome.org> | 2000-02-14 14:34:33 +0000 |
commit | 75958ce2abf778330758063f8b3e3d3aecdee3fc (patch) | |
tree | 845a43ca7e2216d670fef382fe01709a431b9650 | |
parent | 20bbc17f6b7ad1837f5b3d4ce269ec8c58837c3d (diff) | |
download | libgtop-75958ce2abf778330758063f8b3e3d3aecdee3fc.tar.gz |
Make sure we close all open files.
-rw-r--r-- | sysdeps/linux/glibtop_server.h | 5 | ||||
-rw-r--r-- | sysdeps/linux/netload.c | 5 | ||||
-rw-r--r-- | sysdeps/linux/procargs.c | 3 |
3 files changed, 10 insertions, 3 deletions
diff --git a/sysdeps/linux/glibtop_server.h b/sysdeps/linux/glibtop_server.h index 50b18f31..e96b1169 100644 --- a/sysdeps/linux/glibtop_server.h +++ b/sysdeps/linux/glibtop_server.h @@ -69,10 +69,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/netload.c b/sysdeps/linux/netload.c index f8b1c8ec..75cd1ab6 100644 --- a/sysdeps/linux/netload.c +++ b/sysdeps/linux/netload.c @@ -290,7 +290,10 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf, } /* Should never happen. */ - if (fields < 2) return; + if (fields < 2) { + fclose (f); + return; + } fields--; while (fgets (buffer, BUFSIZ-1, f)) { diff --git a/sysdeps/linux/procargs.c b/sysdeps/linux/procargs.c index 9473c3e1..5436bbdb 100644 --- a/sysdeps/linux/procargs.c +++ b/sysdeps/linux/procargs.c @@ -60,6 +60,8 @@ glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf, retval = glibtop_malloc_r (server, max_len+1); len = read (cmdline, retval, max_len); + close (cmdline); + if (len < 0) { glibtop_free_r (server, retval); return NULL; @@ -76,6 +78,7 @@ glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf, while (1) { len = read (cmdline, buffer, BUFSIZ-1); if (len < 0) { + close (cmdline); glibtop_free_r (server, retval); return NULL; } |