From f38af725c21e4beab01070ffe73180ca0549129e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 16 Nov 2020 16:50:08 +0100 Subject: Silence theoretical memory leak In practice systemctl should never return multiple SystemState= lines. --- linux/SystemdMeter.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'linux/SystemdMeter.c') diff --git a/linux/SystemdMeter.c b/linux/SystemdMeter.c index 368d5cca..ef88275f 100644 --- a/linux/SystemdMeter.c +++ b/linux/SystemdMeter.c @@ -206,8 +206,10 @@ static void updateViaExec(void) { while (fgets(lineBuffer, sizeof(lineBuffer), commandOutput)) { if (String_startsWith(lineBuffer, "SystemState=")) { char* newline = strchr(lineBuffer + strlen("SystemState="), '\n'); - if (newline) + if (newline) { *newline = '\0'; + } + free(systemState); systemState = xStrdup(lineBuffer + strlen("SystemState=")); } else if (String_startsWith(lineBuffer, "NFailedUnits=")) { nFailedUnits = strtoul(lineBuffer + strlen("NFailedUnits="), NULL, 10); -- cgit v1.2.3