diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-12-08 23:05:51 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-12-08 23:05:51 +0200 |
commit | 7bc05c7755523cdb1222463e5e3c9e71f6906f18 (patch) | |
tree | 1b91db542b7a5f2b1849d7e775920dd04a85ca83 | |
parent | dd3598aa1d82c29132a24663781738fd321ceb8c (diff) | |
download | mailutils-7bc05c7755523cdb1222463e5e3c9e71f6906f18.tar.gz mailutils-7bc05c7755523cdb1222463e5e3c9e71f6906f18.tar.bz2 |
Fix eventual dangling pointers
Don't set mu_log_tag, leave that to the caller.
* libmailutils/cli/cli.c (mu_cli_ext): Don't set mu_log_tag.
* libmailutils/stdstream/strerr.c: Use MU_LOG_TAG macro from
syslog.h
* sieve/sieve.c: Redo --no-program-name support
-rw-r--r-- | libmailutils/cli/cli.c | 9 | ||||
-rw-r--r-- | libmailutils/stdstream/strerr.c | 2 | ||||
-rw-r--r-- | sieve/sieve.c | 24 |
3 files changed, 18 insertions, 17 deletions
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c index 557a9a6cd..0381f9c0f 100644 --- a/libmailutils/cli/cli.c +++ b/libmailutils/cli/cli.c @@ -500,16 +500,9 @@ mu_cli_ext (int argc, char **argv, hints.flags &= ~MU_CFHINT_PER_USER_FILE; /* Set program name */ - if (hints.flags & MU_CFHINT_PROGRAM) - { - if (!mu_log_tag) - mu_log_tag = (char*)hints.program; - } - else + if (!(hints.flags & MU_CFHINT_PROGRAM)) { mu_set_program_name (argv[0]); - if (!mu_log_tag) - mu_log_tag = (char*)mu_program_name; hints.program = (char*) mu_program_name; hints.flags |= MU_CFHINT_PROGRAM; } diff --git a/libmailutils/stdstream/strerr.c b/libmailutils/stdstream/strerr.c index 52fa80eaa..68300417a 100644 --- a/libmailutils/stdstream/strerr.c +++ b/libmailutils/stdstream/strerr.c @@ -117,7 +117,7 @@ mu_stdstream_strerr_setup (int type) if (mu_stdstream_strerr_create (&str, type, mu_log_facility, LOG_ERR, - mu_log_tag, NULL) == 0) + MU_LOG_TAG (), NULL) == 0) { if (mu_log_print_severity) { diff --git a/sieve/sieve.c b/sieve/sieve.c index 591a7353c..483130709 100644 --- a/sieve/sieve.c +++ b/sieve/sieve.c @@ -59,6 +59,7 @@ int dry_run; static int sieve_print_locus = 1; /* Should the log messages include the locus */ +static int no_program_name; static void modify_debug_flags (mu_debug_level_t set, mu_debug_level_t clr) @@ -124,13 +125,6 @@ cli_email (struct mu_parseopt *po, struct mu_option *opt, char const *arg) mu_parseopt_error (po, _("invalid email: %s"), mu_strerror (rc)); } -static void -cli_no_program_name (struct mu_parseopt *po, struct mu_option *opt, - char const *arg) -{ - mu_log_tag = NULL; -} - static struct mu_option sieve_options[] = { { "dry-run", 'n', NULL, MU_OPTION_DEFAULT, N_("do not execute any actions, just print what would be done"), @@ -168,7 +162,7 @@ static struct mu_option sieve_options[] = { mu_c_bool, &expression_option }, { "no-program-name", 0, NULL, MU_OPTION_DEFAULT, N_("do not prefix diagnostic messages with the program name"), - mu_c_string, NULL, cli_no_program_name }, + mu_c_int, &no_program_name }, MU_OPTION_END }, *options[] = { sieve_options, NULL }; @@ -414,6 +408,20 @@ main (int argc, char *argv[]) mu_cli (argc, argv, &cli, sieve_capa, NULL, &argc, &argv); if (dry_run) verbose++; + + if (no_program_name) + { + mu_stream_t errstr; + + mu_log_tag = NULL; + rc = mu_stdstream_strerr_create (&errstr, MU_STRERR_STDERR, 0, 0, + NULL, NULL); + if (rc == 0) + { + mu_stream_destroy (&mu_strerr); + mu_strerr = errstr; + } + } if (argc == 0) { |