Skip to content

Commit ad1ff02

Browse files
committed
Free C-string allocard by strdup after use
This resource leak was found by Coverity scan.
1 parent e982562 commit ad1ff02

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

judge/runguard.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,12 +806,14 @@ void setrestrictions()
806806

807807
/* Set additional environment variables. */
808808
for (const auto &tokens : environment_variables) {
809-
char *token = strtok(strdup(tokens.c_str()), ";");
809+
char *tokens_dup = strdup(tokens.c_str());
810+
char *token = strtok(tokens_dup, ";");
810811
while (token != nullptr) {
811812
verbose("setting environment variable: %s", token);
812813
putenv(token);
813814
token = strtok(nullptr, ";");
814815
}
816+
free(tokens_dup);
815817
}
816818

817819
/* Set resource limits: must be root to raise hard limits.

0 commit comments

Comments
 (0)