Show
Ignore:
Timestamp:
13/05/10 17:30:03 (2 years ago)
Author:
westram
Message:
  • This patch stuffs all memory leaks in ARBDB (as far as covered by unit-tests) for DEBUG and NDEBUG version!
  • ARBDB global data (aka 'gb_local')
    • track number of opened/closed DBs
    • GBK_install_SIGSEGV_handler only once in GB_init_gb()
    • when closing last DB -> call GB_exit_gb() freeing more memory (also called atexit, including assertion failing if a DB is still open)
    • added class ARBDB_memory_manager (just calls gbm_init_mem + gbm_flush_mem)
    • GB_exit_gb flushes ARBDB_memory_manager (if all blocks were freed by gbm_free_mem, everything will be flushed)
  • fixed a few more static buffer leaks
  • gb_make_entry - alloc correct blocksizes for GB_STRING and GB_LINK
  • fixed a hack in gb_read_bin_rek_V2
    • was increasing size of memory block to avoid illegal memory access in decompress (introduced in [1003]; may occur again)
    • due to mismatch in size between gbm_get_mem and gbm_free_mem memory was never flushed even if all blocks have been freed
  • fixed memleak in gb_read_bin_rek_V2
    • when loading mapfile, previously created 'gb_main' was not freed
  • added allocation logger to admalloc.cxx (inactive - use TRACE_ALLOCS to activate it)
    • traces all allocs/frees of ARBDB managed memory
    • detects wrong usage (double free, size and index mismatch) and shows were the block was allocated
    • added new backtrace functions helpful for debugging (store stack-backtraces and print them later)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ARBDB/ad_load.cxx

    r6649 r6654  
    945945            case GB_INTS: 
    946946            case GB_FLOATS: 
    947                 size = gb_read_number(in); 
    948                 memsize =  gb_read_number(in); 
     947                size    = gb_read_number(in); 
     948                memsize = gb_read_number(in); 
     949 
    949950                DEBUG_DUMP_INDENTED(deep, GBS_global_string("size=%li memsize=%li", size, memsize)); 
    950951                if (GB_CHECKINTERN(size, memsize)) { 
     
    954955                else { 
    955956                    GB_SETEXTERN(gb2); 
    956                     p = gbm_get_mem((size_t)memsize+1, GB_GBM_INDEX(gb2)); // ralf: added +1 because decompress ran out of this block 
     957                    // memsize++; // ralf: added +1 because decompress ran out of this block (cant solve like this - breaks memory management!) 
     958                    p = gbm_get_mem((size_t)memsize, GB_GBM_INDEX(gb2));  
    957959                } 
    958960                i = fread(p, 1, (size_t)memsize, in); 
     
    12001202 
    12011203                        gb_main_array[new_idx] = Main; 
     1204 
     1205                        gbm_free_mem((char*)Main->data, sizeof(GBCONTAINER), GB_QUARK_2_GBMINDEX(Main, 0)); 
     1206 
    12021207                        Main->data = newGbd; 
    12031208                        father->main_idx = new_idx; 
     
    13781383    bool           dbCreated           = false; 
    13791384 
    1380     GBK_install_SIGSEGV_handler(true); 
    1381  
    13821385    if (!opent) opentype = gb_open_all; 
    13831386    else if (strchr(opent, 'w')) opentype = gb_open_all; 
     
    14511454    } 
    14521455 
    1453     gbm_init_mem(); 
     1456    if (GB_install_pid(1)) return 0; 
     1457     
    14541458    GB_init_gb(); 
    1455  
    1456     if (GB_install_pid(1)) return 0; 
    14571459 
    14581460    Main = gb_make_gb_main_type(path);