mirror of
https://github.com/Cisco-Talos/clamav.git
synced 2025-10-19 10:23:17 +00:00
Tests: Fix a couple of valgrind complaints (#1554)
Fix valgrind issues regarding: - Unclosed log file descriptor in libclamav unit test program. Also need to disable debug logging for `iconv_cache_destroy()` for this or else it will try to use that file descriptor after `main()` exits. - Unclosed socket file descriptor in ClamDScan when doing `ping()` function. CLAM-2872
This commit is contained in:
parent
47b9e08e1a
commit
d758c00537
3 changed files with 16 additions and 4 deletions
|
@ -175,7 +175,7 @@ int16_t ping_clamd(const struct optstruct *opts)
|
|||
char *errchk = NULL;
|
||||
uint64_t i = 0;
|
||||
const struct optstruct *opt = NULL;
|
||||
int64_t sockd;
|
||||
int64_t sockd = -1;
|
||||
struct RCVLN rcv;
|
||||
uint16_t ret = 0;
|
||||
|
||||
|
@ -227,6 +227,7 @@ int16_t ping_clamd(const struct optstruct *opts)
|
|||
if (sendln(sockd, zPING, sizeof(zPING))) {
|
||||
logg(LOGG_DEBUG, "PING failed...\n");
|
||||
closesocket(sockd);
|
||||
sockd = -1;
|
||||
} else {
|
||||
if (!optget(opts, "wait")->enabled) {
|
||||
logg(LOGG_INFO, "PONG\n");
|
||||
|
@ -262,6 +263,9 @@ int16_t ping_clamd(const struct optstruct *opts)
|
|||
}
|
||||
|
||||
done:
|
||||
if (sockd >= 0) {
|
||||
closesocket(sockd);
|
||||
}
|
||||
if (attempt_str) {
|
||||
free(attempt_str);
|
||||
}
|
||||
|
|
|
@ -526,9 +526,11 @@ static void iconv_cache_init(struct iconv_cache* cache)
|
|||
static void iconv_cache_destroy(struct iconv_cache* cache)
|
||||
{
|
||||
size_t i;
|
||||
cli_dbgmsg(MODULE_NAME "Destroying iconv pool:%p\n", (void*)cache);
|
||||
// Don't use cli_dbgmsg() in destroy, because this happens *after* main() exits and we've already closed the log file handle.
|
||||
//printf(MODULE_NAME "Destroying iconv pool:%p\n", (void*)cache);
|
||||
for (i = 0; i < cache->last; i++) {
|
||||
cli_dbgmsg(MODULE_NAME "closing iconv:%p\n", cache->tab[i]);
|
||||
// Don't log on destroy, because this happens *after* main() exits and we've already closed the log file handle.
|
||||
//printf(MODULE_NAME "closing iconv:%p\n", cache->tab[i]);
|
||||
iconv_close(cache->tab[i]);
|
||||
}
|
||||
cli_hashtab_clear(&cache->hashtab);
|
||||
|
|
|
@ -2012,6 +2012,7 @@ int main(int argc, char **argv)
|
|||
int nf;
|
||||
Suite *s;
|
||||
SRunner *sr;
|
||||
FILE *log_file = NULL;
|
||||
|
||||
UNUSEDPARAM(argc);
|
||||
UNUSEDPARAM(argv);
|
||||
|
@ -2037,7 +2038,8 @@ int main(int argc, char **argv)
|
|||
srunner_add_suite(sr, test_bytecode_suite());
|
||||
|
||||
srunner_set_log(sr, OBJDIR PATHSEP "test.log");
|
||||
if (freopen(OBJDIR PATHSEP "test-stderr.log", "w+", stderr) == NULL) {
|
||||
log_file = freopen(OBJDIR PATHSEP "test-stderr.log", "w+", stderr);
|
||||
if (log_file == NULL) {
|
||||
// The stderr FILE pointer may be closed by `freopen()` even if redirecting to the log file files.
|
||||
// So we will output the error message to stdout instead.
|
||||
fputs("Unable to redirect stderr!\n", stdout);
|
||||
|
@ -2052,5 +2054,9 @@ int main(int argc, char **argv)
|
|||
|
||||
xmlCleanupParser();
|
||||
|
||||
if (log_file) {
|
||||
fclose(log_file);
|
||||
}
|
||||
|
||||
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue