Permalink
Browse files

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)
  • Loading branch information...
1 parent 7face3e commit b820bbbe4b5fedeb88e7798cfdddec722936c34c @mrash committed Feb 10, 2013
Showing with 57 additions and 3 deletions.
  1. +7 −1 server/replay_cache.c
  2. +50 −2 test/test-fwknop.pl
@@ -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
View
@@ -765,6 +765,19 @@
{
'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',
'detail' => 'permissions check cycle (tcp/22)',
'err_msg' => 'could not complete SPA cycle',
'function' => \&permissions_check,
@@ -3475,6 +3488,26 @@ ()
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 @@ ()
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 @@ ()
&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";

0 comments on commit b820bbb

Please sign in to comment.