Hi,<br>In all of your modifications you will lose the new pointer if the call is successful. In this case you are left with the original pointer which is invalid! I think the purpose of ped_realloc has been to wrap this so that you wouldn't need to use a temporary variable and check the return value. The correct use would be something like this:
<br><br>void* tmp;<br>tmp = ped_realloc(fs->gd, new_size);<br>if(tmp == NULL) ....;<br>else fs->gd = tmp;<br><br>Regards,<br>Siavosh<br><div><span class="gmail_quote"><br>On 10/30/07, <b class="gmail_sendername">Frodo Baggins
</b> <<a href="mailto:frodo.drogo@gmail.com">frodo.drogo@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi all,
<br>This point was raised in an earlier discussion on this list. I think<br>the modifications to ext2_resize.c can benefit from a review.<br><br>Regards,<br>Frodo B<br><br>diff --git a/include/parted/parted.h b/include/parted/parted.h
<br>index 1302d8f..13a7bb4 100644<br>--- a/include/parted/parted.h<br>+++ b/include/parted/parted.h<br>@@ -53,7 +53,7 @@ extern const char* ped_get_version ();<br><br> extern void* ped_malloc (size_t size);<br> extern void* ped_calloc (size_t size);
<br>-extern int ped_realloc (void** ptr, size_t size);<br>+extern void* ped_realloc (void* ptr, size_t size);<br> extern void ped_free (void* ptr);<br><br> #ifdef __cplusplus<br>diff --git a/libparted/fs/ext2/ext2_resize.c b/libparted/fs/ext2/ext2_resize.c
<br>index 580c466..b637c23 100644<br>--- a/libparted/fs/ext2/ext2_resize.c<br>+++ b/libparted/fs/ext2/ext2_resize.c<br>@@ -35,7 +35,7 @@ static int ext2_add_group(struct ext2_fs *fs, blk_t groupsize)<br> if (fs->opt_verbose)
<br> fputs ("ext2_add_group\n", stderr);<br><br>- if (!ped_realloc ((void*) &fs->gd,<br>+ if (NULL == ped_realloc ((void*) fs->gd,<br> (fs->numgroups+1) * sizeof(struct ext2_group_desc)
<br> + fs->blocksize))<br> return 0;</blockquote><div><br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
@@ -315,7 +315,7 @@ static int ext2_del_group(struct ext2_fs *fs)<br> if (fs->opt_safe)<br> ext2_sync(fs);<br><br>- ped_realloc ((void*) &fs->gd,<br>+ ped_realloc ((void*) fs->gd,
<br> fs->numgroups * sizeof(struct ext2_group_desc)<br> + fs->blocksize);<br><br>diff --git a/libparted/libparted.c b/libparted/libparted.c<br>index a8c7f0a..978f219 100644
<br>--- a/libparted/libparted.c<br>+++ b/libparted/libparted.c<br>@@ -308,19 +308,18 @@ ped_malloc (size_t size)<br> return mem;<br> }<br><br>-int<br>-ped_realloc (void** old, size_t size)<br>+void*<br>+ped_realloc (void* old, size_t size)
<br> {<br> void* mem;<br><br>- mem = (void*) realloc (*old, size);<br>+ mem = realloc (old, size);<br> if (!mem) {<br> ped_exception_throw (PED_EXCEPTION_FATAL, PED_EXCEPTION_CANCEL,
<br> _("Out of memory."));<br>- return 0;<br>+ return mem;<br> }<br>- *old = mem;<br>- return 1;<br>+ return mem;<br> }<br>
<br><br>diff --git a/parted/parted.c b/parted/parted.c<br>index 6a606ae..65ccef4 100644<br>--- a/parted/parted.c<br>+++ b/parted/parted.c<br>@@ -1171,7 +1171,7 @@ partition_print_flags (PedPartition* part)<br> first_flag = 0;
<br> else {<br> _res = res;<br>- ped_realloc (&_res, strlen (res)<br>+ ped_realloc (_res, strlen (res)
<br> + 1 + 2);<br> res = _res;<br> strncat (res, ", ", 2);<br>@@ -1179,7 +1179,7 @@ partition_print_flags (PedPartition* part)
<br><br> name = _(ped_partition_flag_get_name (flag));<br> _res = res;<br>- ped_realloc (&_res, strlen (res) + 1<br>+ ped_realloc (_res, strlen (res) + 1
<br> + strlen (name));<br> res = _res;<br> strncat (res, name, 21);<br><br>_______________________________________________
<br>parted-devel mailing list<br><a href="mailto:parted-devel@lists.alioth.debian.org">parted-devel@lists.alioth.debian.org</a><br><a href="http://lists.alioth.debian.org/mailman/listinfo/parted-devel">http://lists.alioth.debian.org/mailman/listinfo/parted-devel
</a><br></blockquote></div><br>