From: Andrew Cooper <Andrew.Cooper3@citrix.com>
To: Viktor Mitin <viktor.mitin.19@gmail.com>,
Ian Campbell <Ian.Campbell@citrix.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: Re: libxc: memory leak in handle_hvm_context
Date: Fri, 17 May 2019 12:23:49 +0000 [thread overview]
Message-ID: <1558095829281.70695@citrix.com> (raw)
In-Reply-To: <CAOcoXZbz6Yfjc=U+MEAPWL0g+wc44FpipM+AmrKJGMYeQPteJw@mail.gmail.com>
(Apologies for use of outlook - I'm having email problems atm).
There is no memory leak at all.
x = memcpy(y, ...);
is an "x = y;" assignment in disguise. Recall that memcpy() returns y, and isn't a void function.
~Andrew
________________________________________
From: Viktor Mitin <viktor.mitin.19@gmail.com>
Sent: 17 May 2019 12:56
To: Andrew Cooper; Ian Campbell; xen-devel@lists.xenproject.org
Cc: Volodymyr Babchuk
Subject: Re: libxc: memory leak in handle_hvm_context
There is no memory leak in case when handle_hvm_context function is
called next time.
So the code seems ok, please ignore the mail, sorry for confusion.
Thanks
On Fri, May 17, 2019 at 2:49 PM Viktor Mitin <viktor.mitin.19@gmail.com> wrote:
>
> Hi All,
>
> It seems there is a memory leak in libxc function handle_hvm_context
> (in file tools/libxc/xc_sr_restore_x86_hvm.c.). There is a malloc of
> variable p without free.
> Please take a look.
>
> +/*
> + * Process an HVM_CONTEXT record from the stream.
> + */
> +static int handle_hvm_context(struct xc_sr_context *ctx,
> + struct xc_sr_record *rec)
> +{
> + xc_interface *xch = ctx->xch;
> + void *p;
> +
> + p = malloc(rec->length);
> + if ( !p )
> + {
> + ERROR("Unable to allocate %u bytes for hvm context", rec->length);
> + return -1;
> + }
> +
> + free(ctx->x86_hvm.restore.context);
> +
> + ctx->x86_hvm.restore.context = memcpy(p, rec->data, rec->length);
> + ctx->x86_hvm.restore.contextsz = rec->length;
> +
> + return 0;
> +}
>
> Thanks
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
WARNING: multiple messages have this Message-ID (diff)
From: Andrew Cooper <Andrew.Cooper3@citrix.com>
To: Viktor Mitin <viktor.mitin.19@gmail.com>,
Ian Campbell <Ian.Campbell@citrix.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: Re: [Xen-devel] libxc: memory leak in handle_hvm_context
Date: Fri, 17 May 2019 12:23:49 +0000 [thread overview]
Message-ID: <1558095829281.70695@citrix.com> (raw)
Message-ID: <20190517122349.XIOVjJ8WFoF4r_l5h7xvWBjAoGbUUcw3XF6dwu2mrEk@z> (raw)
In-Reply-To: <CAOcoXZbz6Yfjc=U+MEAPWL0g+wc44FpipM+AmrKJGMYeQPteJw@mail.gmail.com>
(Apologies for use of outlook - I'm having email problems atm).
There is no memory leak at all.
x = memcpy(y, ...);
is an "x = y;" assignment in disguise. Recall that memcpy() returns y, and isn't a void function.
~Andrew
________________________________________
From: Viktor Mitin <viktor.mitin.19@gmail.com>
Sent: 17 May 2019 12:56
To: Andrew Cooper; Ian Campbell; xen-devel@lists.xenproject.org
Cc: Volodymyr Babchuk
Subject: Re: libxc: memory leak in handle_hvm_context
There is no memory leak in case when handle_hvm_context function is
called next time.
So the code seems ok, please ignore the mail, sorry for confusion.
Thanks
On Fri, May 17, 2019 at 2:49 PM Viktor Mitin <viktor.mitin.19@gmail.com> wrote:
>
> Hi All,
>
> It seems there is a memory leak in libxc function handle_hvm_context
> (in file tools/libxc/xc_sr_restore_x86_hvm.c.). There is a malloc of
> variable p without free.
> Please take a look.
>
> +/*
> + * Process an HVM_CONTEXT record from the stream.
> + */
> +static int handle_hvm_context(struct xc_sr_context *ctx,
> + struct xc_sr_record *rec)
> +{
> + xc_interface *xch = ctx->xch;
> + void *p;
> +
> + p = malloc(rec->length);
> + if ( !p )
> + {
> + ERROR("Unable to allocate %u bytes for hvm context", rec->length);
> + return -1;
> + }
> +
> + free(ctx->x86_hvm.restore.context);
> +
> + ctx->x86_hvm.restore.context = memcpy(p, rec->data, rec->length);
> + ctx->x86_hvm.restore.contextsz = rec->length;
> +
> + return 0;
> +}
>
> Thanks
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-05-17 12:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-17 11:49 libxc: memory leak in handle_hvm_context Viktor Mitin
2019-05-17 11:49 ` [Xen-devel] " Viktor Mitin
2019-05-17 11:56 ` Viktor Mitin
2019-05-17 11:56 ` [Xen-devel] " Viktor Mitin
2019-05-17 12:23 ` Andrew Cooper [this message]
2019-05-17 12:23 ` Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1558095829281.70695@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=viktor.mitin.19@gmail.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.