[PATCH] Replace some malloc and strdup by xmalloc and xstrdup respectively

David Vazquez xeos at gmail.com
Tue Jun 12 19:25:47 UTC 2007


I replace some malloc and strdup by xmalloc and xstrdup respectively.

Signed-off-by: David Vazquez <xeos at gmail.com>
---
 parted/command.c |    3 ++-
 parted/parted.c  |    3 ++-
 parted/strlist.c |   11 ++++++-----
 parted/table.c   |    2 +-
 4 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/parted/command.c b/parted/command.c
index 7ce9090..a5c4998 100644
--- a/parted/command.c
+++ b/parted/command.c
@@ -25,6 +25,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include "xalloc.h"
 
 Command*
 command_create (const StrList* names,
@@ -35,7 +36,7 @@ command_create (const StrList* names,
 {
 	Command*	cmd;
 
-	cmd = malloc (sizeof (Command));
+	cmd = xmalloc (sizeof (Command));
         
         if (non_interactive)
                 cmd->non_interactive = 1;
diff --git a/parted/parted.c b/parted/parted.c
index 8f15ce9..73be7a4 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -51,6 +51,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <limits.h>
+#include "xalloc.h"
 
 #ifdef ENABLE_MTRACE
 #include <mcheck.h>
@@ -1314,7 +1315,7 @@ do_print (PedDevice** dev)
                         ped_free (end);
                 }    
 
-                dev_name = strdup ((*dev)->path);
+                dev_name = xstrdup ((*dev)->path);
                 ped_device_free_all ();
 
                 *dev = ped_device_get (dev_name);
diff --git a/parted/strlist.c b/parted/strlist.c
index 7739e9b..7ddd692 100644
--- a/parted/strlist.c
+++ b/parted/strlist.c
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
+#include "xalloc.h"
 
 #ifdef ENABLE_NLS
 
@@ -97,7 +98,7 @@ wchar_strdup (const wchar_t* str)
 #ifdef ENABLE_NLS
 	return wcsdup (str);
 #else
-	return strdup (str);
+	return xstrdup (str);
 #endif
 }
 
@@ -136,7 +137,7 @@ error:
 static wchar_t*
 gettext_to_wchar (const char* str)
 {
-	return strdup (str);
+	return xstrdup (str);
 }
 
 #endif /* !ENABLE_NLS */
@@ -187,7 +188,7 @@ wchar_to_str (const wchar_t* str, size_t count)
 {
 	char*		result;
 
-	result = strdup (str);
+	result = xstrdup (str);
 	if (count && count < strlen (result))
 		result [count] = 0;
 	return result;
@@ -208,7 +209,7 @@ str_list_alloc ()
 {
 	StrList*	list;
 
-	list = (StrList*) malloc (sizeof (StrList));
+	list = (StrList*) xmalloc (sizeof (StrList));
 	list->next = NULL;
 
 	return list;
@@ -360,7 +361,7 @@ str_list_convert (const StrList* list)
 	const StrList*	walk;
 	int		pos = 0;
 	int		length = 1;
-	char*		str = strdup ("");
+	char*		str = xstrdup ("");
 
 	for (walk = list; walk; walk = walk->next) {
 		if (walk->str) {
diff --git a/parted/table.c b/parted/table.c
index 3c2edf2..f4f779c 100644
--- a/parted/table.c
+++ b/parted/table.c
@@ -44,7 +44,7 @@
 #       define wcslen strlen
 #       define wcswidth strnlen
 #       define wcscat strcat
-#       define wcsdup strdup
+#       define wcsdup xstrdup
 #endif
 
 
-- 
1.5.1.4




More information about the parted-devel mailing list