]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: keep header generators independent on connection
authorKarel Zak <kzak@redhat.com>
Thu, 12 Oct 2017 12:21:27 +0000 (14:21 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 12 Oct 2017 12:21:27 +0000 (14:21 +0200)
* avoid memory leaks
* don't use incomplete or header after free()

Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/logger.c

index ea4bcf0b39ce1e55f212c69858d2c3edd638985f..862b8a48bbec55c476754e7bf88f788ac17f29bf 100644 (file)
@@ -523,8 +523,6 @@ static void syslog_rfc3164_header(struct logger_ctl *const ctl)
        char pid[30], *hostname;
 
        *pid = '\0';
-       if (ctl->fd < 0)
-               return;
        if (ctl->pid)
                snprintf(pid, sizeof(pid), "[%d]", ctl->pid);
 
@@ -752,9 +750,6 @@ static void syslog_rfc5424_header(struct logger_ctl *const ctl)
        char *structured = NULL;
        struct list_head *sd;
 
-       if (ctl->fd < 0)
-               return;
-
        if (ctl->rfc5424_time) {
                struct timeval tv;
                struct tm *tm;
@@ -881,6 +876,7 @@ static void syslog_local_header(struct logger_ctl *const ctl)
 static void generate_syslog_header(struct logger_ctl *const ctl)
 {
        free(ctl->hdr);
+       ctl->hdr = NULL;
        ctl->syslogfp(ctl);
 }