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:
Michael Rash
2013-02-10 14:57:44 -05:00
parent 7face3eec9
commit b820bbbe4b
2 changed files with 57 additions and 3 deletions
+7 -1
View File
@@ -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