From 50d1de13cbabb9e0de0b674deb9d068880c7d0d8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Nov 2014 19:29:27 +0100 Subject: [PATCH] libnm: don't heap allocate uuid temporary variable --- libnm-core/nm-utils.c | 8 +++----- libnm-util/nm-utils.c | 11 ++++------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index d27a0251b4..409d4dcc1e 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -1961,18 +1961,16 @@ nm_utils_uuid_generate (void) char * nm_utils_uuid_generate_from_string (const char *s) { - uuid_t *uuid; + uuid_t uuid; char *buf = NULL; g_return_val_if_fail (s && *s, NULL); - uuid = g_malloc0 (sizeof (*uuid)); - crypto_md5_hash (NULL, 0, s, strlen (s), (char *) uuid, sizeof (*uuid)); + crypto_md5_hash (NULL, 0, s, strlen (s), (char *) uuid, sizeof (uuid)); buf = g_malloc0 (37); - uuid_unparse_lower (*uuid, &buf[0]); + uuid_unparse_lower (uuid, &buf[0]); - g_free (uuid); return buf; } diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index 2cbac34d3a..cde29976ce 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -1487,7 +1487,7 @@ char * nm_utils_uuid_generate_from_string (const char *s) { GError *error = NULL; - uuid_t *uuid; + uuid_t uuid; char *buf = NULL; g_return_val_if_fail (s && *s, NULL); @@ -1501,21 +1501,18 @@ nm_utils_uuid_generate_from_string (const char *s) return NULL; } - uuid = g_malloc0 (sizeof (*uuid)); - if (!crypto_md5_hash (NULL, 0, s, strlen (s), (char *) uuid, sizeof (*uuid), &error)) { + if (!crypto_md5_hash (NULL, 0, s, strlen (s), (char *) uuid, sizeof (uuid), &error)) { g_warning ("error generating UUID: (%d) %s", error ? error->code : 0, error ? error->message : "unknown"); if (error) g_error_free (error); - goto out; + return NULL; } buf = g_malloc0 (37); - uuid_unparse_lower (*uuid, &buf[0]); + uuid_unparse_lower (uuid, &buf[0]); -out: - g_free (uuid); return buf; }