diff --git a/ChangeLog b/ChangeLog index 314ffeaf7a43be55628b48f13d0f6a4653c4c605..498353f94f7c8169d8f2b675632a9644e5da7344 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,22 @@ 2005-12-27 Per Cederqvist + + Don't overestimate the number of conferences as next_free_num when + allocating certain data structures. (Bug 164). + * src/server/simple-cache.c (existing_confs): New static + variable. + (cached_no_of_existing_conferences): Return existing_confs, + instead of overestimating the number of conferences as + next_free_num. (Bug 164). + (cached_create_conf): Increase existing_confs. + (cached_delete_conf): Decrease existing_confs. + (init_cache): Increase existing_confs when a new conference is + created. + (free_all_cache): Decrease existing_confs when conferences are + deallocated. + (dump_cache_mem_usage): Dump existing_confs. + * src/server/testsuite/config/unix.exp (check_memory_usage): Check + the dump of existing_confs. Fail if allocated_strings or + allocated_blocks isn't found in the file. Simplified the name parsing routing, and save some small amount of memory, by removing the priority field of Matching_info. diff --git a/src/server/simple-cache.c b/src/server/simple-cache.c index b75ac12d81de6ef65dcbda0b54c136a89b3b61be..750700c018e76282a071797f662cfb3a09488c79 100644 --- a/src/server/simple-cache.c +++ b/src/server/simple-cache.c @@ -110,6 +110,7 @@ static Small_conf ** small_conf_arr; static Cache_node_mcb * pers_mcb; static Cache_node_mcb * conf_mcb; static Conf_no next_free_num = 1; +static Conf_no existing_confs = 0; static Cache_node_mcb * text_mcb; static Text_no next_text_num = 1; @@ -439,12 +440,7 @@ cached_get_conf_supervisor(Conf_no conf_no) extern Conf_no cached_no_of_existing_conferences(void) { - return next_free_num; /* This is too large, but who cares? */ - /* Actually, this is used in lookup_regexp (and maybe other - places) to allocate an array this large, and that is pretty - stupid if many conferences have been deleted. But it is no big - deal. Not yet, anyhow... */ - /* FIXME (bug 164): We should return a better estimate. */ + return existing_confs; } /* @@ -789,6 +785,8 @@ cached_create_conf (String name) return 0; } + ++existing_confs; + create_cache_node (conf_mcb, conf_no); node = get_conf_node (conf_no); @@ -854,6 +852,8 @@ cached_delete_conf( Conf_no conf ) node->ptr = NULL; node->s.exists = 0; + --existing_confs; + LOGACC(lt_delete_conf, conf); rebuild_matching_info_entry(conf); @@ -2804,6 +2804,7 @@ init_cache(void) create_cache_node(conf_mcb, num); node = get_conf_node(num); update_stat(STAT_CONFS, 1); + ++existing_confs; } node->s.exists = 1; @@ -3004,6 +3005,7 @@ free_all_cache (void) { free_small_conf (small_conf_arr[i]); small_conf_arr[i] = NULL; + --existing_confs; } } @@ -3171,7 +3173,8 @@ EXPORT void dump_cache_mem_usage(FILE *fp) { fprintf(fp, "---simple-cache.c:\n"); - fprintf(fp, "\tSmall_confs: %d\n", no_of_allocated_small_confs); + fprintf(fp, "\tSmall_confs: %d\n", no_of_allocated_small_confs); + fprintf(fp, "\tExisting confs: %d\n", existing_confs); } diff --git a/src/server/testsuite/config/unix.exp b/src/server/testsuite/config/unix.exp index ddf077f84326f392ef503c6e6b9c7622249f890e..9a2683040b872aaa954ec4855b2412f7c667d99e 100644 --- a/src/server/testsuite/config/unix.exp +++ b/src/server/testsuite/config/unix.exp @@ -870,8 +870,9 @@ proc lyskomd_fail_start {log_messages proc check_memory_usage {} { global memix - set allocated_strings 0 - set allocated_blocks 0 + set allocated_strings unknown + set allocated_blocks unknown + set existing_confs unknown set f [ open "etc/memory-usage" ] while { [ gets $f line] >= 0 } { @@ -879,7 +880,9 @@ proc check_memory_usage {} { set allocated_blocks [lindex "$line" [expr [llength "$line"] - 1]] } elseif { [regexp "Allocated strings" $line] } { set allocated_strings [lindex "$line" [expr [llength "$line"] - 1]] - } + } elseif { [regexp "Existing confs:" $line] } { + set existing_confs [lindex "$line" [expr [llength "$line"] - 1]] + } } close $f @@ -898,6 +901,11 @@ proc check_memory_usage {} { } else { pass "Allocated strings on exit" } + if { $existing_confs != 0 } { + fail "Existing conferences on exit" + } else { + pass "Existing conferences on exit" + } } proc parse_valgrind_leak {f} {