libnm: don't heap allocate uuid temporary variable

This commit is contained in:
Thomas Haller 2014-11-27 19:29:27 +01:00
parent e67425347a
commit 50d1de13cb
2 changed files with 7 additions and 12 deletions

View file

@ -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;
}

View file

@ -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;
}