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
1 changed files with 3 additions and 1 deletions

View File

@ -206,8 +206,10 @@ static void updateViaExec(void) {
while (fgets(lineBuffer, sizeof(lineBuffer), commandOutput)) { while (fgets(lineBuffer, sizeof(lineBuffer), commandOutput)) {
if (String_startsWith(lineBuffer, "SystemState=")) { if (String_startsWith(lineBuffer, "SystemState=")) {
char* newline = strchr(lineBuffer + strlen("SystemState="), '\n'); char* newline = strchr(lineBuffer + strlen("SystemState="), '\n');
if (newline) if (newline) {
*newline = '\0'; *newline = '\0';
}
free(systemState);
systemState = xStrdup(lineBuffer + strlen("SystemState=")); systemState = xStrdup(lineBuffer + strlen("SystemState="));
} else if (String_startsWith(lineBuffer, "NFailedUnits=")) { } else if (String_startsWith(lineBuffer, "NFailedUnits=")) {
nFailedUnits = strtoul(lineBuffer + strlen("NFailedUnits="), NULL, 10); nFailedUnits = strtoul(lineBuffer + strlen("NFailedUnits="), NULL, 10);