[hackers] [skvm] Some streams were not closed on occassions. || Dimitrios Papastamos

From: <hg_AT_suckless.org>
Date: Fri, 15 May 2009 23:45:26 +0000 (UTC)

changeset: 14:1d904f1e324d
tag: tip
user: Dimitrios Papastamos <stateless [at] archlinux.us>
date: Sat May 16 00:45:02 2009 -0700
files: skvm.c
description:
Some streams were not closed on occassions.

diff -r 56c21f2aa16a -r 1d904f1e324d skvm.c
--- a/skvm.c Thu May 14 20:52:13 2009 -0700
+++ b/skvm.c Sat May 16 00:45:02 2009 -0700
@@ -659,7 +659,7 @@
 
 static int
 remove_fstab_entry(const struct device_t *device) {
- FILE *fstab, *line_pp;
+ FILE *fstab = NULL, *line_pp = NULL;
    char buf[BUFSIZ];
    int lines = 0, i = 0;
 
@@ -669,8 +669,12 @@
    line_pp = popen("wc -l /etc/fstab | awk '{print $1}'", "r");
    if (!line_pp)
       return -1;
- if (!fgets(buf, sizeof buf, line_pp))
+
+ if (!fgets(buf, sizeof buf, line_pp)) {
+ pclose(line_pp);
       return -1;
+ }
+
    pclose(line_pp);
    lines = atoi(buf);
 
@@ -682,11 +686,14 @@
    while (!feof(fstab) && fgets(tmp[i], BUFSIZ, fstab))
       ++i;
 
+ if (ferror(fstab))
+ goto fail;
+
    rewind(fstab);
    if (ftruncate(fileno(fstab), 0) < 0) {
       syslog(LOG_ERR, "%s:%d: %s", __FILE__, __LINE__,
              strerror(errno));
- return -1;
+ goto fail;
    }
 
    i = 0;
@@ -698,6 +705,11 @@
 
    fclose(fstab);
    return 0;
+
+fail:
+ if (fstab)
+ pclose(fstab);
+ return -1;
 }
 
 static inline int
Received on Fri May 15 2009 - 23:45:26 UTC

This archive was generated by hypermail 2.2.0 : Fri May 15 2009 - 23:48:05 UTC