Skip to content

Commit ef83313

Browse files
committed
Prevent a memory leak
1 parent dae96d3 commit ef83313

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

utils/oscap-xccdf.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,10 @@ static bool _system_is_in_bootc_mode(void)
604604
}
605605
size_t buf_size = CHUNK_SIZE;
606606
char *buf = calloc(buf_size, sizeof(char));
607+
if (buf == NULL) {
608+
pclose(output);
609+
return false;
610+
}
607611
int c;
608612
size_t i = 0;
609613
while ((c = fgetc(output)) != EOF) {
@@ -619,7 +623,9 @@ static bool _system_is_in_bootc_mode(void)
619623
buf[i++] = c;
620624
}
621625
pclose(output);
622-
return *buf != '\0' && strstr(buf, "\"booted\":null") == NULL;
626+
bool result = (*buf != '\0' && strstr(buf, "\"booted\":null") == NULL);
627+
free(buf);
628+
return result;
623629
#endif
624630
}
625631

0 commit comments

Comments
 (0)