OSDN Git Service

linux: don't leak a FILE* upon /proc read failure
authorJim Meyering <meyering@redhat.com>
Fri, 27 May 2011 11:53:36 +0000 (13:53 +0200)
committerJim Meyering <meyering@redhat.com>
Fri, 27 May 2011 11:53:36 +0000 (13:53 +0200)
* libparted/arch/linux.c (_probe_proc_partitions): Call fclose
upon failure.

libparted/arch/linux.c

index 6ce6a3f..aeaf98f 100644 (file)
@@ -2064,16 +2064,17 @@ _probe_proc_partitions ()
         char            buf [512];
         char            part_name [256];
         char            dev_name [256];
+        int ok = 0;
 
         proc_part_file = fopen ("/proc/partitions", "r");
         if (!proc_part_file)
                 return 0;
 
         if (fgets (buf, 256, proc_part_file) == NULL)
-                return 0;
+                goto done;
 
         if (fgets (buf, 256, proc_part_file) == NULL)
-                return 0;
+                goto done;
 
         while (fgets (buf, 512, proc_part_file)
                && sscanf (buf, "%d %d %d %255s", &major, &minor, &size,
@@ -2090,8 +2091,10 @@ _probe_proc_partitions ()
                 _ped_device_probe (dev_name);
         }
 
+        ok = 1;
+ done:
         fclose (proc_part_file);
-        return 1;
+        return ok;
 }
 
 struct _entry {