diff options
author | Thomas Haller <thaller@redhat.com> | 2022-05-02 16:34:06 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-09-29 15:22:56 +0200 |
commit | c598f0ff0fbbb0b09008c662e5e1f0ebd7bb3932 (patch) | |
tree | e3b5e4201065a9a4a9563ea38b3bdae38d28d784 | |
parent | 06e720f7b2211e1bdf194b820ae0d8dde3d55a0f (diff) | |
download | NetworkManager-c598f0ff0fbbb0b09008c662e5e1f0ebd7bb3932.tar.gz |
core: transfer ownership of strbuf data in _fw_nft_set()
In practice there is little difference.
Previously, "strbuf" would own the string until the end of the function,
when the "nm_auto_str_buf" cleanup attribute destroys it. In the
meantime, we would pass it on to _fw_nft_call_sync(), which in fact
won't access the string after returning.
Instead, we can just transfer ownership to the GBytes instance. That seems
more logical and safer than aliasing the buffer owned by NMStrBuf with
a g_bytes_new_static(). That way, we don't add a non-obvious restriction
on the lifetime of the string. The lifetime is now guarded by the GBytes
instance, which, could be referenced and kept alive longer.
There is also no runtime/memory overhead in doing this.
(cherry picked from commit 6a04bcc59d4bdcb545353071ecc4891570e9f4e2)
-rw-r--r-- | src/core/nm-firewall-utils.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/src/core/nm-firewall-utils.c b/src/core/nm-firewall-utils.c index 8fa8059e00..1311f50399 100644 --- a/src/core/nm-firewall-utils.c +++ b/src/core/nm-firewall-utils.c @@ -679,8 +679,7 @@ _fw_nft_set(gboolean add, const char *ip_iface, in_addr_t addr, guint8 plen) NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, &ss1)); - stdin_buf = g_bytes_new_static(nm_str_buf_get_str(&strbuf), strbuf.len); - + stdin_buf = nm_str_buf_finalize_to_gbytes(&strbuf); _fw_nft_call_sync(stdin_buf, NULL); } |