[parted-devel] [RFC][PATCH] Remove alloca from libparted/arch/linux.c
Frodo Baggins
frodo.drogo at gmail.com
Wed Sep 5 18:08:22 UTC 2007
Is this safe/desirable?
Regards,
Frodo B
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 648bd2b..9d54e3f 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -307,7 +307,7 @@ readFD (int fd, char **buf)
size_t size = PROC_DEVICES_BUFSIZ;
int s, filesize = 0;
- *buf = malloc (size * sizeof (char));
+ *buf = ped_malloc (size * sizeof (char));
if (*buf == 0) {
return -1;
}
@@ -320,16 +320,16 @@ readFD (int fd, char **buf)
break;
filesize += s;
size += s;
- *buf = realloc (*buf, size);
+ *buf = ped_realloc (*buf, size);
} while (1);
if (filesize == 0 && s < 0) {
- free (*buf);
+ ped_free (*buf);
*buf = NULL;
return -1;
} else {
/* there is always some excess memory left unused */
- *buf = realloc (*buf, filesize+1);
+ *buf = ped_realloc (*buf, filesize+1);
(*buf)[filesize] = '\0';
}
@@ -2214,7 +2214,7 @@ static int
_dm_is_part (struct dm_info *this, char *name)
{
struct dm_task* task = NULL;
- struct dm_info* info = alloca(sizeof *info);
+ struct dm_info* info = NULL;
struct dm_deps* deps = NULL;
int rc = 0;
unsigned int i;
@@ -2231,15 +2231,17 @@ _dm_is_part (struct dm_info *this, char
}
rc = 0;
- memset(info, '\0', sizeof *info);
- dm_task_get_info(task, info);
- if (!info->exists)
- goto err;
-
- deps = dm_task_get_deps(task);
- if (!deps)
+ info=ped_malloc(sizeof (struct dm_info));
+ if(NULL!=info){
+ memset(info, '\0', sizeof *info);
+ dm_task_get_info(task, info);
+ if (!info->exists)
goto err;
-
+ }
+ deps = dm_task_get_deps(task);
+ if (!deps)
+ goto err;
+
rc = 0;
for (i = 0; i < deps->count; i++) {
unsigned int ma = major(deps->device[i]),
@@ -2251,6 +2253,9 @@ _dm_is_part (struct dm_info *this, char
err:
dm_task_destroy(task);
+ if(NULL!=info){
+ ped_free(info);
+ }
return rc;
}
More information about the parted-devel
mailing list