don't leak FILEs
authorEric Andersen <andersen@codepoet.org>
Fri, 20 Sep 2002 07:33:18 +0000 (07:33 -0000)
committerEric Andersen <andersen@codepoet.org>
Fri, 20 Sep 2002 07:33:18 +0000 (07:33 -0000)
procps/top.c

index 8e5767e4105dbc0487a3f8b4400fe1ed5ef295c7..f6bbb23cdc9ab99149c85fd6cb5af509150c09ff 100644 (file)
@@ -212,6 +212,8 @@ static void read_status(int num, status_t *s)
                fp = fopen(status, "r");
                if (!fp) {
                        strncpy(s->pid, "EXIT", sizeof(s->pid));
+                       s->pid[sizeof(s->pid)-1] = '\0';
+                       fclose(fp);
                        continue;
                }
 
@@ -296,6 +298,7 @@ static status_t *read_info(int num, struct dirent **namelist)
                sprintf(cmdline, "%s/cmdline", s->pid);
                fp = fopen(cmdline, "r");
                if (!fp) {
+                       fclose(fp);
                        perror("fopen('cmdline')");
                        return NULL;
                }