Implemented memory clean up for digest cache list

Upon fwknopd shutdown, a new function free_replay_list() is now called in order
to free heap allocated memory dedicated to SPA digest tracking.  Without this
fix, valgrind reports the following (some output snipped):

valgrind --leak-check=full ./server/.libs/fwknopd -f -i lo -P "udp port 62201"

==30864== 431 (48 direct, 383 indirect) bytes in 1 blocks are definitely lost in loss record 17 of 17
==30864==    at 0x4C27480: calloc (vg_replace_malloc.c:467)
==30864==    by 0x407CB7: replay_check_file_cache (replay_cache.c:461)
==30864==    by 0x407B69: replay_check (replay_cache.c:413)
==30864==    by 0x405813: incoming_spa (incoming_spa.c:363)
==30864==    by 0x406275: pcap_capture (pcap_capture.c:223)
==30864==    by 0x40317D: main (fwknopd.c:297)
This commit is contained in:
Michael Rash
2011-08-14 19:42:50 -04:00
parent 5ee6715cff
commit 878fae8e8a
3 changed files with 38 additions and 0 deletions
+5
View File
@@ -366,6 +366,11 @@ main(int argc, char **argv)
*/
fw_cleanup();
free_logging();
#if USE_FILE_CACHE
free_replay_list(&opts);
#endif
free_configs(&opts);
return(0);
+32
View File
@@ -619,4 +619,36 @@ replay_check_dbm_cache(fko_srv_options_t *opts, fko_ctx_t ctx)
}
#endif /* USE_FILE_CACHE */
#if USE_FILE_CACHE
/* Free replay list memory
*/
void
free_replay_list(fko_srv_options_t *opts)
{
#ifdef NO_DIGEST_CACHE
return;
#endif
struct digest_cache_list *digest_list_ptr = NULL, *digest_tmp = NULL;
if (opts->digest_cache == NULL)
return;
digest_list_ptr = opts->digest_cache;
while (digest_list_ptr != NULL)
{
digest_tmp = digest_list_ptr->next;
if (digest_list_ptr->cache_info.digest != NULL
&& digest_list_ptr->cache_info.digest[0] != '\0')
{
free(digest_list_ptr->cache_info.digest);
}
free(digest_list_ptr);
digest_list_ptr = digest_tmp;
}
return;
}
#endif
/***EOF***/
+1
View File
@@ -63,6 +63,7 @@ int replay_check(fko_srv_options_t *opts, fko_ctx_t ctx);
#ifdef USE_FILE_CACHE
int replay_file_cache_init(fko_srv_options_t *opts);
int replay_check_file_cache(fko_srv_options_t *opts, fko_ctx_t ctx);
void free_replay_list(fko_srv_options_t *opts);
#else
int replay_db_cache_init(fko_srv_options_t *opts);
int replay_check_dbm_cache(fko_srv_options_t *opts, fko_ctx_t ctx);