summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-05-02 16:34:06 +0200
committerThomas Haller <thaller@redhat.com>2022-05-02 16:43:42 +0200
commit6a04bcc59d4bdcb545353071ecc4891570e9f4e2 (patch)
treecc6a8eb26c9203cb444147f4c5af8c16803a2ee7
parent04ce34d8dc98658279150c0137a96591a36764b4 (diff)
downloadNetworkManager-6a04bcc59d4bdcb545353071ecc4891570e9f4e2.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.
-rw-r--r--src/core/nm-firewall-utils.c3
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);
}