Always own ctl.command by using xstrdup() for the -c optarg path
(the -- path already allocates via ul_strv_join), and free both
ctl.command and ctl.command_norm at exit.
Signed-off-by: Karel Zak <kzak@redhat.com>
const char *ttyname;
const char *ttytype;
- const char *command;
+ char *command;
char *command_norm; /* normalized (without \n) */
int ttycols;
int ttylines;
ctl.append = 1;
break;
case 'c':
- ctl.command = optarg;
+ free(ctl.command);
+ ctl.command = xstrdup(optarg);
+ free(ctl.command_norm);
ctl.command_norm = xstrdup(ctl.command);
ul_strrep(ctl.command_norm, '\n', ' ');
break;
utempter_remove_record(ul_pty_get_childfd(ctl.pty));
#endif
ul_free_pty(ctl.pty);
+ free(ctl.command);
+ free(ctl.command_norm);
/* default exit code */
rc = rc ? EXIT_FAILURE : EXIT_SUCCESS;