diff options
author | Brad King <brad.king@kitware.com> | 2024-10-23 23:12:51 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-10-26 09:47:19 (GMT) |
commit | be540dbe19caf16818f6db5bf51d7c1dd2cd1b60 (patch) | |
tree | 1f15de75c3390b1f5e9c6946b54bc43f04756ec2 /Tests | |
parent | 6fdb15672d99694e94467d82232f964982f82f5b (diff) | |
download | CMake-be540dbe19caf16818f6db5bf51d7c1dd2cd1b60.zip CMake-be540dbe19caf16818f6db5bf51d7c1dd2cd1b60.tar.gz CMake-be540dbe19caf16818f6db5bf51d7c1dd2cd1b60.tar.bz2 |
Tests: Fix FILE stream leaks in helper programs
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/detect_jobserver.c | 2 | ||||
-rw-r--r-- | Tests/RunCMake/pseudo_llvm-rc.c | 16 |
2 files changed, 11 insertions, 7 deletions
diff --git a/Tests/RunCMake/detect_jobserver.c b/Tests/RunCMake/detect_jobserver.c index 67cc7db..04fb1f2 100644 --- a/Tests/RunCMake/detect_jobserver.c +++ b/Tests/RunCMake/detect_jobserver.c @@ -162,6 +162,7 @@ int main(int argc, char** argv) jobserver = jobserver_auth(message); if (jobserver == NULL) { + fclose(fp); fprintf(stderr, "%s\n", message); return 1; } @@ -171,6 +172,7 @@ int main(int argc, char** argv) #else result = posix(jobserver, message); #endif + fclose(fp); free(jobserver); message[MAX_MESSAGE_LENGTH] = '\0'; diff --git a/Tests/RunCMake/pseudo_llvm-rc.c b/Tests/RunCMake/pseudo_llvm-rc.c index 65f0a9e..e495e8d 100644 --- a/Tests/RunCMake/pseudo_llvm-rc.c +++ b/Tests/RunCMake/pseudo_llvm-rc.c @@ -9,6 +9,8 @@ int main(int argc, char* argv[]) { FILE* source; FILE* target; + char buffer[500]; + size_t n; int i; for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "-bad") == 0) { @@ -22,13 +24,13 @@ int main(int argc, char* argv[]) return 1; } target = fopen(argv[argc - 2], "wb"); - if (target != NULL) { - char buffer[500]; - size_t n = fread(buffer, 1, sizeof(buffer), source); - fwrite(buffer, 1, n, target); + if (target == NULL) { fclose(source); - fclose(target); - return 0; + return 1; } - return 1; + n = fread(buffer, 1, sizeof(buffer), source); + fwrite(buffer, 1, n, target); + fclose(source); + fclose(target); + return 0; } |