Whamcloud - gitweb
ismounted.c (is_swap_device): Fix file descriptor/memory leak;
authorTheodore Ts'o <tytso@mit.edu>
Fri, 22 Feb 2002 01:48:25 +0000 (20:48 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 22 Feb 2002 01:48:25 +0000 (20:48 -0500)
we were missing an fclose().

lib/ext2fs/ChangeLog
lib/ext2fs/ismounted.c

index e32db2d..1b10a07 100644 (file)
@@ -1,10 +1,16 @@
+2002-02-21  Theodore Tso  <tytso@valinux.com>
+
+       * ismounted.c (is_swap_device): Fix file descriptor/memory leak;
+               we were missing an fclose().
+
 2002-02-20  Theodore Tso  <tytso@valinux.com>
 
        * Makefile.in, inode_io.c, ext2fs.h, ext2_err.et.in: Add new io
                abstraction interface which exports an ext2 inode.
 
-       * fileio.c (ext2fs_file_flush): Export ext2fs_file_flush as a
-               public interface.
+       * ext2fs.h, fileio.c (ext2fs_file_flush): Export ext2fs_file_flush
+               as a public interface.  Change void * to const void * in
+               ext2fs_file_write's interface.
 
        * test_io.c (test_close), unix_io.c (unix_close): Remove unneeded
                conditional; save a few bytes.
index dd853e2..858d08e 100644 (file)
@@ -155,6 +155,7 @@ static int is_swap_device(const char *file)
        char            buf[1024], *cp;
        dev_t           file_dev;
        struct stat     st_buf;
+       int             ret = 0;
 
        file_dev = 0;
 #ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */
@@ -162,8 +163,7 @@ static int is_swap_device(const char *file)
                file_dev = st_buf.st_rdev;
 #endif 
 
-       f = fopen("/proc/swaps", "r");
-       if (!f)
+       if (!(f = fopen("/proc/swaps", "r")))
                return 0;
        /* Skip the first line */
        fgets(buf, sizeof(buf), f);
@@ -174,15 +174,20 @@ static int is_swap_device(const char *file)
                        *cp = 0;
                if ((cp = strchr(buf, '\t')) != NULL)
                        *cp = 0;
-               if (strcmp(buf, file) == 0)
-                       return 1;
+               if (strcmp(buf, file) == 0) {
+                       ret++;
+                       break;
+               }
 #ifndef __GNU__
                if (file_dev && (stat(buf, &st_buf) == 0) &&
-                   file_dev == st_buf.st_rdev)
-                       return 1;
+                   file_dev == st_buf.st_rdev) {
+                       ret++;
+                       break;
+               }
 #endif
        }
-       return 0;
+       fclose(f);
+       return ret;
 }
 
 static errcode_t check_mntent(const char *file, int *mount_flags,