summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-03-03 13:23:01 +0100
committerThomas Haller <thaller@redhat.com>2017-03-03 13:23:01 +0100
commit9e429ddc0abe1bd9936880751c6f979cfc84fada (patch)
treef0ae68fdf80efe8348aefecc3897f418a5a3ff00
parenta81b604cc1e9d8eb5c91c581129c9b74c843253e (diff)
dnsmasq: reuse string buffer in creating command line arguments in create_dm_cmd_line()
-rw-r--r--src/dnsmasq/nm-dnsmasq-manager.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/dnsmasq/nm-dnsmasq-manager.c b/src/dnsmasq/nm-dnsmasq-manager.c
index 9b24e69eb..267d6b36a 100644
--- a/src/dnsmasq/nm-dnsmasq-manager.c
+++ b/src/dnsmasq/nm-dnsmasq-manager.c
@@ -152,7 +152,7 @@ create_dm_cmd_line (const char *iface,
GError **error)
{
NMCmdLine *cmd;
- GString *s;
+ nm_auto_free_gstring GString *s = NULL;
char first[INET_ADDRSTRLEN];
char last[INET_ADDRSTRLEN];
char localaddr[INET_ADDRSTRLEN];
@@ -167,6 +167,8 @@ create_dm_cmd_line (const char *iface,
if (!dm_binary)
return NULL;
+ s = g_string_sized_new (100);
+
/* Create dnsmasq command line */
cmd = nm_cmd_line_new ();
nm_cmd_line_add_string (cmd, dm_binary);
@@ -196,11 +198,11 @@ create_dm_cmd_line (const char *iface,
*/
nm_cmd_line_add_string (cmd, "--strict-order");
- s = g_string_new ("--listen-address=");
nm_utils_inet4_ntop (listen_address->address, localaddr);
+ g_string_append (s, "--listen-address=");
g_string_append (s, localaddr);
nm_cmd_line_add_string (cmd, s->str);
- g_string_free (s, TRUE);
+ g_string_truncate (s, 0);
if (!nm_dnsmasq_utils_get_range (listen_address, first, last, &error_desc)) {
g_set_error_literal (error,
@@ -213,24 +215,23 @@ create_dm_cmd_line (const char *iface,
return NULL;
}
- s = g_string_new ("--dhcp-range=");
- g_string_append_printf (s, "%s,%s,60m", first, last);
+ g_string_append_printf (s, "--dhcp-range=%s,%s,60m", first, last);
nm_cmd_line_add_string (cmd, s->str);
- g_string_free (s, TRUE);
+ g_string_truncate (s, 0);
if (!nm_ip4_config_get_never_default (ip4_config)) {
- s = g_string_new ("--dhcp-option=option:router,");
+ g_string_append (s, "--dhcp-option=option:router,");
g_string_append (s, localaddr);
nm_cmd_line_add_string (cmd, s->str);
- g_string_free (s, TRUE);
+ g_string_truncate (s, 0);
}
nm_cmd_line_add_string (cmd, "--dhcp-lease-max=50");
- s = g_string_new ("--pid-file=");
+ g_string_append (s, "--pid-file=");
g_string_append (s, pidfile);
nm_cmd_line_add_string (cmd, s->str);
- g_string_free (s, TRUE);
+ g_string_truncate (s, 0);
/* dnsmasq exits if the conf dir is not present */
if (g_file_test (CONFDIR, G_FILE_TEST_IS_DIR))