Patchwork [2/6] file_ram_alloc(): use g_strdup_printf() instead of asprintf()

login
register
mail settings
Submitter Eduardo Habkost
Date July 2, 2012, 6:06 p.m.
Message ID <1341252398-12268-3-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/168623/
State New
Headers show

Comments

Eduardo Habkost - July 2, 2012, 6:06 p.m.
Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 exec.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
Blue Swirl - July 3, 2012, 7:16 p.m.
On Mon, Jul 2, 2012 at 6:06 PM, Eduardo Habkost <ehabkost@redhat.com> wrote:
> Cc: Blue Swirl <blauwirbel@gmail.com>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

Acked-by: Blue Swirl <blauwirbel@gmail.com>

> ---
>  exec.c |   14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index c8bfd27..d856325 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -24,6 +24,9 @@
>  #include <sys/mman.h>
>  #endif
>
> +#include <glib.h>
> +#include <glib/gprintf.h>
> +
>  #include "qemu-common.h"
>  #include "cpu.h"
>  #include "tcg.h"
> @@ -2357,7 +2360,7 @@ static void *file_ram_alloc(RAMBlock *block,
>                              ram_addr_t memory,
>                              const char *path)
>  {
> -    char *filename;
> +    gchar *filename;
>      void *area;
>      int fd;
>  #ifdef MAP_POPULATE
> @@ -2379,18 +2382,15 @@ static void *file_ram_alloc(RAMBlock *block,
>          return NULL;
>      }
>
> -    if (asprintf(&filename, "%s/qemu_back_mem.XXXXXX", path) == -1) {
> -        return NULL;
> -    }
> -
> +    filename = g_strdup_printf("%s/qemu_back_mem.XXXXXX", path);
>      fd = mkstemp(filename);
>      if (fd < 0) {
>          perror("unable to create backing store for hugepages");
> -        free(filename);
> +        g_free(filename);
>          return NULL;
>      }
>      unlink(filename);
> -    free(filename);
> +    g_free(filename);
>
>      memory = (memory + hpagesize - 1) & ~(hpagesize - 1);
>
> --
> 1.7.10.4
>

Patch

diff --git a/exec.c b/exec.c
index c8bfd27..d856325 100644
--- a/exec.c
+++ b/exec.c
@@ -24,6 +24,9 @@ 
 #include <sys/mman.h>
 #endif
 
+#include <glib.h>
+#include <glib/gprintf.h>
+
 #include "qemu-common.h"
 #include "cpu.h"
 #include "tcg.h"
@@ -2357,7 +2360,7 @@  static void *file_ram_alloc(RAMBlock *block,
                             ram_addr_t memory,
                             const char *path)
 {
-    char *filename;
+    gchar *filename;
     void *area;
     int fd;
 #ifdef MAP_POPULATE
@@ -2379,18 +2382,15 @@  static void *file_ram_alloc(RAMBlock *block,
         return NULL;
     }
 
-    if (asprintf(&filename, "%s/qemu_back_mem.XXXXXX", path) == -1) {
-        return NULL;
-    }
-
+    filename = g_strdup_printf("%s/qemu_back_mem.XXXXXX", path);
     fd = mkstemp(filename);
     if (fd < 0) {
         perror("unable to create backing store for hugepages");
-        free(filename);
+        g_free(filename);
         return NULL;
     }
     unlink(filename);
-    free(filename);
+    g_free(filename);
 
     memory = (memory + hpagesize - 1) & ~(hpagesize - 1);