diff mbox

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

Message ID 1341252398-12268-3-git-send-email-ehabkost@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

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

Comments

Blue Swirl July 3, 2012, 7:16 p.m. UTC | #1
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
>
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

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);