qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 2/5] tests: Prepare virtio-blk-test for multi


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH v2 2/5] tests: Prepare virtio-blk-test for multi-arch implementation
Date: Mon, 17 Nov 2014 15:21:10 +0000
User-agent: Mutt/1.5.23 (2014-03-12)

On Sat, Nov 01, 2014 at 06:02:27PM +0100, Marc Marí wrote:
> Modularize functions in virtio-blk-test and add PCI suffix for PCI specific
> components.
> 
> Signed-off-by: Marc Marí <address@hidden>
> ---
>  tests/virtio-blk-test.c |   57 
> +++++++++++++++++++++++++++++++----------------
>  1 file changed, 38 insertions(+), 19 deletions(-)
> 
> diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
> index 33e8094..6f07d5a 100644
> --- a/tests/virtio-blk-test.c
> +++ b/tests/virtio-blk-test.c
> @@ -55,11 +55,11 @@ typedef struct QVirtioBlkReq {
>      uint8_t status;
>  } QVirtioBlkReq;
>  
> -static QPCIBus *test_start(void)
> +static char *drive_create(void)
>  {
> -    char *cmdline;
> -    char tmp_path[] = "/tmp/qtest.XXXXXX";
>      int fd, ret;
> +    char *tmp_path = malloc(18);
> +    strncpy(tmp_path, "/tmp/qtest.XXXXXX", 18);

Please use g_strdup():
https://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-strdup

QEMU does not use malloc(3)/free(3) directly.  Always use glib memory
allocation (in this case g_strdup() allocates memory for you).

>  
>      /* Create a temporary raw image */
>      fd = mkstemp(tmp_path);
> @@ -68,6 +68,16 @@ static QPCIBus *test_start(void)
>      g_assert_cmpint(ret, ==, 0);
>      close(fd);
>  
> +    return tmp_path;
> +}
> +
> +static QPCIBus *pci_test_start(void)
> +{
> +    char *cmdline;
> +    char *tmp_path;
> +
> +    tmp_path = drive_create();

It seems tmp_path is leaked.  You must free dynamically allocated
memory!

Attachment: pgp2973mYBWin.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]