diff --git a/src/common/log.c b/src/common/log.c
index 6c63019f7c..80f413c0ae 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -480,8 +480,7 @@ new_severity_list(int loglevelMin, int loglevelMax)
}
/** Add a log handler named name to send all messages in severity
- * to stream. Steals a reference to severity; the caller must
- * not use it after calling this function. Helper: does no locking. */
+ * to stream. Copies severity. Helper: does no locking. */
static void
add_stream_log_impl(log_severity_list_t *severity,
const char *name, FILE *stream)
@@ -489,7 +488,7 @@ add_stream_log_impl(log_severity_list_t *severity,
logfile_t *lf;
lf = tor_malloc_zero(sizeof(logfile_t));
lf->filename = tor_strdup(name);
- lf->severities = severity;
+ lf->severities = tor_memdup(severity, sizeof(log_severity_list_t));
lf->file = stream;
lf->next = logfiles;
@@ -539,7 +538,7 @@ add_callback_log(log_severity_list_t *severity, log_callback cb)
{
logfile_t *lf;
lf = tor_malloc_zero(sizeof(logfile_t));
- lf->severities = severity;
+ lf->severities = tor_memdup(severity, sizeof(log_severity_list_t));
lf->filename = tor_strdup("");
lf->callback = cb;
lf->next = logfiles;
@@ -657,7 +656,7 @@ add_syslog_log(log_severity_list_t *severity)
openlog("Tor", LOG_PID | LOG_NDELAY, LOGFACILITY);
lf = tor_malloc_zero(sizeof(logfile_t));
- lf->severities = severity;
+ lf->severities = tor_memdup(severity, sizeof(log_severity_list_t));
lf->filename = tor_strdup("");
lf->is_syslog = 1;
diff --git a/src/or/config.c b/src/or/config.c
index fc6e4e8228..123fe1d9b3 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -1055,6 +1055,7 @@ options_act_reversible(or_options_t *old_options, char **msg)
close_temp_logs();
add_callback_log(severity, control_event_logmsg);
control_adjust_event_log_severity();
+ tor_free(severity);
}
SMARTLIST_FOREACH(replaced_listeners, connection_t *, conn,
{
@@ -3770,7 +3771,6 @@ options_init_logs(or_options_t *options, int validate_only)
} else {
add_stream_log(severity, err?"":"",
err?stderr:stdout);
- severity=NULL;
}
}
goto cleanup;
@@ -3780,7 +3780,6 @@ options_init_logs(or_options_t *options, int validate_only)
#ifdef HAVE_SYSLOG_H
if (!validate_only) {
add_syslog_log(severity);
- severity=NULL;
}
#else
log_warn(LD_CONFIG, "Syslog is not supported on this system. Sorry.");
@@ -3794,8 +3793,6 @@ options_init_logs(or_options_t *options, int validate_only)
if (add_file_log(severity, smartlist_get(elts, 1)) < 0) {
log_warn(LD_CONFIG, "Couldn't open file for 'Log %s'", opt->value);
ok = 0;
- } else {
- tor_free(severity);
}
}
goto cleanup;