Make sure we close all open files.

This commit is contained in:
Martin Baulig
2000-02-14 14:34:33 +00:00
parent 20bbc17f6b
commit 75958ce2ab
3 changed files with 10 additions and 3 deletions

View File

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

View File

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

View File

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