From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44658) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUMkt-00012M-HR for qemu-devel@nongnu.org; Tue, 25 Aug 2015 18:31:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUMkq-0000Ki-C0 for qemu-devel@nongnu.org; Tue, 25 Aug 2015 18:31:47 -0400 Received: from e39.co.us.ibm.com ([32.97.110.160]:43027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUMkq-0000KH-3a for qemu-devel@nongnu.org; Tue, 25 Aug 2015 18:31:44 -0400 Received: from /spool/local by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 25 Aug 2015 16:31:43 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 5F74719D803E for ; Tue, 25 Aug 2015 16:22:37 -0600 (MDT) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t7PMSo0644695690 for ; Tue, 25 Aug 2015 15:28:50 -0700 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t7PMVf9J016570 for ; Tue, 25 Aug 2015 16:31:41 -0600 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <1440540624-7998-6-git-send-email-marcandre.lureau@redhat.com> References: <1440540624-7998-1-git-send-email-marcandre.lureau@redhat.com> <1440540624-7998-6-git-send-email-marcandre.lureau@redhat.com> Message-ID: <20150825223111.11069.44394@loki> Date: Tue, 25 Aug 2015 17:31:11 -0500 Subject: Re: [Qemu-devel] [PATCH v2 05/12] qga: copy argument strings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org Quoting marcandre.lureau@redhat.com (2015-08-25 17:10:17) > From: Marc-Andr=C3=A9 Lureau > = > A following patch will return allocated string. > = > Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Michael Roth > --- > qga/main.c | 57 +++++++++++++++++++++++++++++++-------------------------- > 1 file changed, 31 insertions(+), 26 deletions(-) > = > diff --git a/qga/main.c b/qga/main.c > index ede5306..83b7804 100644 > --- a/qga/main.c > +++ b/qga/main.c > @@ -944,13 +944,13 @@ static GList *split_list(gchar *str, const gchar se= parator) > int main(int argc, char **argv) > { > const char *sopt =3D "hVvdm:p:l:f:F::b:s:t:"; > - const char *method =3D NULL, *channel_path =3D NULL; > - const char *log_filepath =3D NULL; > - const char *pid_filepath; > + char *method =3D NULL, *channel_path =3D NULL; > + char *log_filepath =3D NULL; > + char *pid_filepath =3D NULL; > #ifdef CONFIG_FSFREEZE > - const char *fsfreeze_hook =3D NULL; > + char *fsfreeze_hook =3D NULL; > #endif > - const char *state_dir; > + char *state_dir =3D NULL; > #ifdef _WIN32 > const char *service =3D NULL; > #endif > @@ -981,31 +981,28 @@ int main(int argc, char **argv) > module_call_init(MODULE_INIT_QAPI); > = > init_dfl_pathnames(); > - pid_filepath =3D dfl_pathnames.pidfile; > - state_dir =3D dfl_pathnames.state_dir; > - > while ((ch =3D getopt_long(argc, argv, sopt, lopt, &opt_ind)) !=3D -= 1) { > switch (ch) { > case 'm': > - method =3D optarg; > + method =3D g_strdup(optarg); > break; > case 'p': > - channel_path =3D optarg; > + channel_path =3D g_strdup(optarg); > break; > case 'l': > - log_filepath =3D optarg; > + log_filepath =3D g_strdup(optarg); > break; > case 'f': > - pid_filepath =3D optarg; > + pid_filepath =3D g_strdup(optarg); > break; > #ifdef CONFIG_FSFREEZE > case 'F': > - fsfreeze_hook =3D optarg ? optarg : QGA_FSFREEZE_HOOK_DEFAUL= T; > + fsfreeze_hook =3D g_strdup(optarg ?: QGA_FSFREEZE_HOOK_DEFAU= LT); > break; > #endif > case 't': > - state_dir =3D optarg; > - break; > + state_dir =3D g_strdup(optarg); > + break; > case 'v': > /* enable all log levels */ > log_level =3D G_LOG_LEVEL_MASK; > @@ -1028,20 +1025,10 @@ int main(int argc, char **argv) > case 's': > service =3D optarg; > if (strcmp(service, "install") =3D=3D 0) { > - const char *fixed_state_dir; > - > - /* If the user passed the "-t" option, we save that stat= e dir > - * in the service. Otherwise we let the service fetch th= e state > - * dir from the environment when it starts. > - */ > - fixed_state_dir =3D (state_dir =3D=3D dfl_pathnames.stat= e_dir) ? > - NULL : > - state_dir; > if (ga_install_vss_provider()) { > exit(EXIT_FAILURE); > } > - if (ga_install_service(channel_path, log_filepath, > - fixed_state_dir)) { > + if (ga_install_service(channel_path, log_filepath, state= _dir)) { > exit(EXIT_FAILURE); > } > exit(EXIT_SUCCESS); > @@ -1072,6 +1059,14 @@ int main(int argc, char **argv) > } > } > = > + if (pid_filepath =3D=3D NULL) { > + pid_filepath =3D g_strdup(dfl_pathnames.pidfile); > + } > + > + if (state_dir =3D=3D NULL) { > + state_dir =3D g_strdup(dfl_pathnames.state_dir); > + } > + > #ifdef _WIN32 > /* On win32 the state directory is application specific (be it the d= efault > * or a user override). We got past the command line parsing; let's = create > @@ -1214,5 +1209,15 @@ out_bad: > if (daemonize) { > unlink(pid_filepath); > } > + > + g_free(method); > + g_free(log_filepath); > + g_free(pid_filepath); > + g_free(state_dir); > + g_free(channel_path); > +#ifdef CONFIG_FSFREEZE > + g_free(fsfreeze_hook); > +#endif > + > return EXIT_FAILURE; > } > -- = > 2.4.3 >=20