Minor memory leak bug fix in --rotate-digest-cache mode
This commit fixes a minor memory leak for the digest cache file path in --rotate-digest-cache mode in the replay_cache_init() function. The leak was caught by valgrind, and a new test was added to the test suite for it. Here is the valgrind warning: ==29021== 21 bytes in 1 blocks are definitely lost in loss record 2 of 2 ==29021== at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==29021== by 0x1103AA: replay_cache_init (replay_cache.c:96) ==29021== by 0x10BB8C: main (fwknopd.c:254)
This commit is contained in:
@@ -109,11 +109,14 @@ rotate_digest_cache_file(fko_srv_options_t *opts)
|
||||
#if USE_FILE_CACHE
|
||||
strlcpy(new_file, opts->config[CONF_DIGEST_FILE],
|
||||
strlen(opts->config[CONF_DIGEST_FILE])+5);
|
||||
strlcat(new_file, "-old",
|
||||
strlen(opts->config[CONF_DIGEST_FILE])+5);
|
||||
#else
|
||||
strlcpy(new_file, opts->config[CONF_DIGEST_DB_FILE],
|
||||
strlen(opts->config[CONF_DIGEST_DB_FILE])+5);
|
||||
strlcat(new_file, "-old",
|
||||
strlen(opts->config[CONF_DIGEST_DB_FILE])+5);
|
||||
#endif
|
||||
strcat(new_file, "-old");
|
||||
|
||||
#if USE_FILE_CACHE
|
||||
res = rename(opts->config[CONF_DIGEST_FILE], new_file);
|
||||
@@ -130,6 +133,9 @@ rotate_digest_cache_file(fko_srv_options_t *opts)
|
||||
#endif
|
||||
);
|
||||
#endif /* NO_DIGEST_CACHE */
|
||||
|
||||
if(new_file != NULL)
|
||||
free(new_file);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -762,6 +762,19 @@ my @tests = (
|
||||
'fw_rule_removed' => $NEW_RULE_REMOVED,
|
||||
'fatal' => $NO
|
||||
},
|
||||
{
|
||||
'category' => 'Rijndael SPA',
|
||||
'subcategory' => 'client+server',
|
||||
'detail' => 'rotate digest file',
|
||||
'err_msg' => 'could not rotate digest file',
|
||||
'function' => \&rotate_digest_file,
|
||||
'cmdline' => $default_client_args,
|
||||
'fwknopd_cmdline' => "LD_LIBRARY_PATH=$lib_dir $valgrind_str " .
|
||||
"$fwknopdCmd $default_server_conf_args $intf_str --rotate-digest-cache",
|
||||
'fw_rule_created' => $NEW_RULE_REQUIRED,
|
||||
'fw_rule_removed' => $NEW_RULE_REMOVED,
|
||||
'fatal' => $NO
|
||||
},
|
||||
{
|
||||
'category' => 'Rijndael SPA',
|
||||
'subcategory' => 'client+server',
|
||||
@@ -3475,6 +3488,26 @@ sub permissions_check() {
|
||||
return $rv;
|
||||
}
|
||||
|
||||
sub rotate_digest_file() {
|
||||
my $test_hr = shift;
|
||||
my $rv = 1;
|
||||
|
||||
$rv = &spa_cycle($test_hr);
|
||||
|
||||
if (-e "${default_digest_file}-old") {
|
||||
### put the file back in place
|
||||
move "${default_digest_file}-old", $default_digest_file;
|
||||
&write_test_file("[+] digest cache file was rotated.\n",
|
||||
$curr_test_file);
|
||||
} else {
|
||||
&write_test_file("[-] rotated digest cache file does not exist.\n",
|
||||
$curr_test_file);
|
||||
$rv = 0;
|
||||
}
|
||||
|
||||
return $rv;
|
||||
}
|
||||
|
||||
sub spa_cycle() {
|
||||
my $test_hr = shift;
|
||||
|
||||
@@ -6646,8 +6679,10 @@ sub init() {
|
||||
push @tests_to_exclude, qr|active/expire sets|;
|
||||
}
|
||||
|
||||
if (-e $default_digest_file) {
|
||||
unlink $default_digest_file;
|
||||
for my $file ($default_digest_file, "${default_digest_file}-old") {
|
||||
if (-e $file) {
|
||||
unlink $file;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -6763,6 +6798,19 @@ sub parse_valgrind_flagged_functions() {
|
||||
|
||||
&import_previous_valgrind_coverage_info();
|
||||
|
||||
if (%prev_valgrind_cov) {
|
||||
&write_test_file("[+] Imported previous valgrind data from: " .
|
||||
"$previous_valgrind_coverage_dir\n", $curr_test_file);
|
||||
} else {
|
||||
if (-d $previous_valgrind_coverage_dir) {
|
||||
&write_test_file("[-] Did not import previous valgrind data " .
|
||||
"from: $previous_valgrind_coverage_dir\n", $curr_test_file);
|
||||
} else {
|
||||
&write_test_file("[-] Previous valgrind data dir does not exist: " .
|
||||
"from: $previous_valgrind_coverage_dir\n", $curr_test_file);
|
||||
}
|
||||
}
|
||||
|
||||
mkdir "$output_dir/$valgrind_cov_dir"
|
||||
unless -d "$output_dir/$valgrind_cov_dir";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user