[Libguestfs] [PATCH] drives: fix deletion of servers on error
Richard W.M. Jones
rjones at redhat.com
Mon Aug 18 16:30:27 UTC 2014
On Mon, Aug 18, 2014 at 02:56:08PM +0200, Pino Toscano wrote:
> Make sure to not skip any of the created server, and to always free
> the "server" array.
> diff --git a/src/drives.c b/src/drives.c
> index 4bd8328..85c1495 100644
> --- a/src/drives.c
> +++ b/src/drives.c
> @@ -743,8 +743,7 @@ parse_servers (guestfs_h *g, char *const *strs,
>
> for (i = 0; i < n; ++i) {
> if (parse_one_server (g, strs[i], &servers[i]) == -1) {
> - if (i > 0)
> - free_drive_servers (servers, i-1);
> + free_drive_servers (servers, i);
> return -1;
> }
> }
> ---
> src/drives.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/src/drives.c b/src/drives.c
> index 4bd8328..85c1495 100644
> --- a/src/drives.c
> +++ b/src/drives.c
> @@ -743,8 +743,7 @@ parse_servers (guestfs_h *g, char *const *strs,
>
> for (i = 0; i < n; ++i) {
> if (parse_one_server (g, strs[i], &servers[i]) == -1) {
> - if (i > 0)
> - free_drive_servers (servers, i-1);
> + free_drive_servers (servers, i);
> return -1;
> }
> }
> --
> 1.9.3
The original code is attempting to avoid a double-free of
servers[i].u.hostname. I think this change would mean the double-free
would happen again.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
More information about the Libguestfs
mailing list