]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
linux/ofpath: fix various memory leaks.
authorAndrei Borzenkov <arvidjaar@gmail.com>
Mon, 26 Jan 2015 18:41:29 +0000 (21:41 +0300)
committerAndrei Borzenkov <arvidjaar@gmail.com>
Mon, 26 Jan 2015 20:04:00 +0000 (23:04 +0300)
Found by: Coverity scan.

grub-core/osdep/linux/ofpath.c

index 8f24bc9e8978fb4317854676543082bee81c9488..4cc171cb505ee424ecb929a0dbc55db87c2dd82a 100644 (file)
@@ -128,6 +128,8 @@ find_obppath (const char *sysfs_path_orig)
 
       if (fd < 0 || fstat (fd, &st) < 0)
        {
+         if (fd >= 0)
+           close (fd);
          kill_trailing_dir(sysfs_path);
          if (!strcmp(sysfs_path, "/sys"))
            {
@@ -147,6 +149,9 @@ find_obppath (const char *sysfs_path_orig)
        {
          grub_util_info (_("cannot read `%s': %s"), path, strerror (errno));
          close(fd);
+         free (path);
+         free (of_path);
+         free (sysfs_path);
          return NULL;
        }
       close(fd);
@@ -480,6 +485,7 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
               snprintf(disk, sizeof (disk),
                        "/sas/%s@%lx,%lu:%c", disk_name, sas_address, longlun, 'a' + (part - 1));
             }
+         free (lunstr);
         }
     }
   strcat(of_path, disk);
@@ -530,7 +536,7 @@ grub_util_devname_to_ofpath (const char *sys_devname)
   else
     {
       grub_util_warn (_("unknown device type %s\n"), device);
-      return NULL;
+      ofpath = NULL;
     }
 
   free (devnode);