mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-19 16:11:32 +00:00
libnm: don't heap allocate uuid temporary variable
This commit is contained in:
parent
e67425347a
commit
50d1de13cb
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue