diff options
author | Shawn Landden <shawn@git.icu> | 2021-01-06 01:09:00 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-06 01:09:00 +0400 |
commit | 033630dfe00951d9511c8c2a3dc17f3c9328cf58 (patch) | |
tree | ba0d992c4e85e84d6b3ffe1d1b0a2512de42e34a | |
parent | e00651b24c328c290e39c5380c3ab99c6c34ed70 (diff) | |
parent | 8225cc46adc2351d8f14f752cdc943cd07f0a2e0 (diff) | |
download | distcc-git-033630dfe00951d9511c8c2a3dc17f3c9328cf58.tar.gz |
Merge pull request #404 from swegener/memory-and-file-descriptor-leaks
Fix memory and file descriptor leaks
-rw-r--r-- | src/daemon.c | 6 | ||||
-rw-r--r-- | src/serve.c | 20 |
2 files changed, 18 insertions, 8 deletions
diff --git a/src/daemon.c b/src/daemon.c index c8fee7c..9bcf94a 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -170,6 +170,12 @@ static void dcc_warn_masquerade_whitelist(void) { rs_log_crit(LIBDIR "/distcc empty. %s", warn); dcc_exit(EXIT_COMPILER_MISSING); } + if (d) { + closedir(d); + } + if (e) { + closedir(e); + } } /** diff --git a/src/serve.c b/src/serve.c index 0f328a8..fc6b782 100644 --- a/src/serve.c +++ b/src/serve.c @@ -403,8 +403,10 @@ static int dcc_check_compiler_whitelist(char *_compiler_name) if (faccessat(dirfd, compiler_name, X_OK, 0) < 0) { char *compiler_path = NULL; - if (asprintf(&compiler_path, "/usr/lib/distcc/%s", compiler_name) && compiler_path) { + if (asprintf(&compiler_path, "/usr/lib/distcc/%s", compiler_name) >= 0) { if (access(compiler_path, X_OK) < 0) { + free(compiler_path); + close(dirfd); rs_log_crit("%s not in %s or %s whitelist.", compiler_name, LIBDIR "/distcc", "/usr/lib/distcc"); return EXIT_BAD_ARGUMENTS; /* ENOENT, EACCESS, etc */ } @@ -412,31 +414,33 @@ static int dcc_check_compiler_whitelist(char *_compiler_name) } } + close(dirfd); + rs_trace("%s in" LIBDIR "/distcc whitelist", compiler_name); return 0; #else // make do with access(): - char *compiler_path = NULL; + char *compiler_path; int ret = 0; - if (asprintf(&compiler_path, "%s/distcc/%s", LIBDIR, compiler_name) && compiler_path) { + if (asprintf(&compiler_path, "%s/distcc/%s", LIBDIR, compiler_name) >= 0) { if (access(compiler_path, X_OK) < 0) { free(compiler_path); /* check /usr/lib/distcc too */ - if (asprintf(&compiler_path, "/usr/lib/distcc/%s", compiler_name) && compiler_path) { + if (asprintf(&compiler_path, "/usr/lib/distcc/%s", compiler_name) >= 0) { if (access(compiler_path, X_OK) < 0) { rs_log_crit("%s not in %s or %s whitelist.", compiler_name, LIBDIR "/distcc", "/usr/lib/distcc"); ret = EXIT_BAD_ARGUMENTS; /* ENOENT, EACCESS, etc */ } + free(compiler_path); } - } + } else { + free(compiler_path); + } rs_trace("%s in" LIBDIR "/distcc whitelist", compiler_name); } else { rs_log_crit("Couldn't check if %s is in %s whitelist.", compiler_name, LIBDIR "/distcc"); ret = EXIT_DISTCC_FAILED; } - if (compiler_path) { - free(compiler_path); - } return ret; #endif } |