Silence theoretical memory leak

In practice systemctl should never return multiple SystemState= lines.
This commit is contained in:
Christian Göttsche 2020-11-16 16:50:08 +01:00
parent fec9af4e6f
commit f38af725c2

View File

@ -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);