summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-08-30 15:40:05 +0200
committerThomas Haller <thaller@redhat.com>2018-09-03 18:07:59 +0200
commit96450f7dbb2286a6c0507df3a677bd42bfaf333a (patch)
treeb186a4416c1f672e82bdd3f0d6b61ee2c53589a4
parent50de8501425701745ba6765a439accad8c9f1ec2 (diff)
downloadNetworkManager-96450f7dbb2286a6c0507df3a677bd42bfaf333a.tar.gz
libnm: avoid intermediate GByteArray in path_to_scheme_value()
It's not that to directly initialize the GBytes without an intermediate GByteArray.
-rw-r--r--libnm-core/nm-setting-8021x.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/libnm-core/nm-setting-8021x.c b/libnm-core/nm-setting-8021x.c
index 7218e7e536..376f86da2c 100644
--- a/libnm-core/nm-setting-8021x.c
+++ b/libnm-core/nm-setting-8021x.c
@@ -664,20 +664,19 @@ nm_setting_802_1x_get_ca_cert_uri (NMSetting8021x *setting)
static GBytes *
path_to_scheme_value (const char *path)
{
- GByteArray *array;
- gsize len;
+ guint8 *mem;
+ gsize len, total_len;
g_return_val_if_fail (path != NULL && path[0], NULL);
len = strlen (path);
+ total_len = (NM_STRLEN (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH) + 1) + len;
/* Add the path scheme tag to the front, then the filename */
- array = g_byte_array_sized_new (len + strlen (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH) + 1);
- g_byte_array_append (array, (const guint8 *) NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH, strlen (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH));
- g_byte_array_append (array, (const guint8 *) path, len);
- g_byte_array_append (array, (const guint8 *) "\0", 1);
-
- return g_byte_array_free_to_bytes (array);
+ mem = g_new (guint8, total_len);
+ memcpy (mem, NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH, NM_STRLEN (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH));
+ memcpy (&mem[NM_STRLEN (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH)], path, len + 1);
+ return g_bytes_new_take (mem, total_len);
}
/**