From dbbc7296f5b9f82319df6cd9f24b3e0cd806f493 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 18 Sep 2015 22:48:45 +0900 Subject: [PATCH] strdup is not required here --- src/shrpx.cc | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index 5675668b..4750c495 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -230,7 +230,7 @@ void exec_binary(SignalServer *ssv) { argv[0] = exec_path; for (int i = 1; i < get_config()->argc; ++i) { - argv[i] = strdup(get_config()->argv[i]); + argv[i] = get_config()->argv[i]; } argv[get_config()->argc] = nullptr; @@ -241,30 +241,32 @@ void exec_binary(SignalServer *ssv) { auto envp = make_unique(envlen + 3 + 1); size_t envidx = 0; - if (get_config()->host_unix) { - std::string fd = ENV_UNIX_FD "="; - fd += util::utos(ssv->server_fd); - envp[envidx++] = strdup(fd.c_str()); + std::string fd, fd6, path, port; - std::string path = ENV_UNIX_PATH "="; + if (get_config()->host_unix) { + fd = ENV_UNIX_FD "="; + fd += util::utos(ssv->server_fd); + envp[envidx++] = &fd[0]; + + path = ENV_UNIX_PATH "="; path += get_config()->host.get(); - envp[envidx++] = strdup(path.c_str()); + envp[envidx++] = &path[0]; } else { if (ssv->server_fd) { - std::string fd4 = ENV_LISTENER4_FD "="; - fd4 += util::utos(ssv->server_fd); - envp[envidx++] = strdup(fd4.c_str()); + fd = ENV_LISTENER4_FD "="; + fd += util::utos(ssv->server_fd); + envp[envidx++] = &fd[0]; } if (ssv->server_fd6) { - std::string fd6 = ENV_LISTENER6_FD "="; + fd6 = ENV_LISTENER6_FD "="; fd6 += util::utos(ssv->server_fd6); - envp[envidx++] = strdup(fd6.c_str()); + envp[envidx++] = &fd6[0]; } - std::string port = ENV_PORT "="; + port = ENV_PORT "="; port += util::utos(get_config()->port); - envp[envidx++] = strdup(port.c_str()); + envp[envidx++] = &port[0]; } for (size_t i = 0; i < envlen; ++i) {