logger: fix memory leak [ASAN and valgrind]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2016-03-13 10:31:40 +00:00 committed by Karel Zak
parent 1d01d13eda
commit 4e5411f623
1 changed files with 3 additions and 1 deletions

View File

@ -341,8 +341,10 @@ static int journald_entry(struct logger_ctl *ctl, FILE *fp)
for (lines = 0; /* nothing */ ; lines++) {
buf = NULL;
sz = getline(&buf, &dummy, fp);
if (sz == -1)
if (sz == -1) {
free(buf);
break;
}
if (0 < sz && buf[sz - 1] == '\n') {
sz--;
buf[sz] = '\0';