OSDN Git Service

device mapper clean-up: remove #ifdefs, plug a leak
authorJim Meyering <meyering@redhat.com>
Fri, 6 Jun 2008 08:10:02 +0000 (10:10 +0200)
committerJim Meyering <meyering@redhat.com>
Fri, 6 Jun 2008 11:36:36 +0000 (13:36 +0200)
* libparted/arch/linux.c: Remove some #ifdef ENABLE_DEVICE_MAPPER
directives.
* include/parted/device.h (struct _PedDevice) [dmtype]: Likewise.
* libparted/arch/linux.c (linux_new): Plug a leak.

include/parted/device.h
libparted/arch/linux.c

index 64b4a0a..42d2593 100644 (file)
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 1998 - 2001, 2005, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1998 - 2001, 2005, 2007-2008 Free Software Foundation, Inc.
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -72,9 +72,7 @@ struct _PedDevice {
 
         PedDeviceType   type;           /**< SCSI, IDE, etc.
                                              \deprecated \sa PedDeviceType */
-#ifdef ENABLE_DEVICE_MAPPER
         char*          dmtype;         /**< device map target type */
-#endif
         long long       sector_size;            /**< logical sector size */
         long long       phys_sector_size;       /**< physical sector size */
         PedSector       length;                 /**< device length (LBA) */
index 04107d8..57af6c7 100644 (file)
@@ -1,5 +1,4 @@
-/*
-    libparted - a library for manipulating disk partitions
+/* libparted - a library for manipulating disk partitions
     Copyright (C) 1999 - 2005, 2007, 2008 Free Software Foundation, Inc.
 
     This program is free software; you can redistribute it and/or modify
@@ -31,6 +30,7 @@
 #include <stdio.h>
 #include <syscall.h>
 #include <unistd.h>
+#include <stdbool.h>
 #include <dirent.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
@@ -1150,7 +1150,6 @@ static PedDevice*
 linux_new (const char* path)
 {
         PedDevice*      dev;
-        char* type;
 
         PED_ASSERT (path != NULL, return NULL);
 
@@ -1233,14 +1232,19 @@ linux_new (const char* path)
                         goto error_free_arch_specific;
                 break;
 
-#ifdef ENABLE_DEVICE_MAPPER
         case PED_DEVICE_DM:
-                if (asprintf(&type, _("Linux device-mapper (%s)"), dev->dmtype) == -1)
-                        goto error_free_arch_specific;
-                if (!init_generic (dev, type))
+                {
+                  char* type;
+                  if (dev->dmtype == NULL
+                      || asprintf(&type, _("Linux device-mapper (%s)"),
+                                  dev->dmtype) == -1)
                         goto error_free_arch_specific;
-                break;
-#endif
+                  bool ok = init_generic (dev, type);
+                  free (type);
+                  if (!ok)
+                    goto error_free_arch_specific;
+                  break;
+                }
 
         case PED_DEVICE_XVD:
                 if (!init_generic (dev, _("Xen Virtual Block Device")))
@@ -1276,9 +1280,7 @@ linux_destroy (PedDevice* dev)
         free (dev->arch_specific);
         free (dev->path);
         free (dev->model);
-#ifdef ENABLE_DEVICE_MAPPER
         free (dev->dmtype);
-#endif
         free (dev);
 }
 
@@ -2024,9 +2026,7 @@ _device_get_part_path (PedDevice* dev, int num)
         } else if (dev->type == PED_DEVICE_DAC960
                         || dev->type == PED_DEVICE_CPQARRAY
                         || dev->type == PED_DEVICE_ATARAID
-#ifdef ENABLE_DEVICE_MAPPER
                         || dev->type == PED_DEVICE_DM
-#endif
                         || isdigit (dev->path[path_len - 1]))
                 snprintf (result, result_len, "%sp%d", dev->path, num);
         else