X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/9242a7e8cfa94bbc9dd7eca6bd651b569b871c4e..1100a343aead3a686a31652d78e4b64dc5e982e5:/src/src/store.c diff --git a/src/src/store.c b/src/src/store.c index c7cf33c9a..b52799132 100644 --- a/src/src/store.c +++ b/src/src/store.c @@ -2,7 +2,7 @@ * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2017 */ +/* Copyright (c) University of Cambridge 1995 - 2018 */ /* See the file NOTICE for conditions of use and distribution. */ /* Exim gets and frees all its store through these functions. In the original @@ -194,7 +194,7 @@ linenumber = linenumber; #else DEBUG(D_memory) { - if (running_in_test_harness) + if (f.running_in_test_harness) debug_printf("---%d Get %5d\n", store_pool, size); else debug_printf("---%d Get %6p %5d %-14s %4d\n", store_pool, @@ -286,7 +286,7 @@ linenumber = linenumber; #else DEBUG(D_memory) { - if (running_in_test_harness) + if (f.running_in_test_harness) debug_printf("---%d Ext %5d\n", store_pool, newsize); else debug_printf("---%d Ext %6p %5d %-14s %4d\n", store_pool, ptr, newsize, @@ -354,10 +354,10 @@ the released memory. */ newlength = bc + b->length - CS ptr; #ifndef COMPILE_UTILITY -if (running_in_test_harness || debug_store) +if (debug_store) { assert_no_variables(ptr, newlength, filename, linenumber); - if (running_in_test_harness) + if (f.running_in_test_harness) { (void) VALGRIND_MAKE_MEM_DEFINED(ptr, newlength); memset(ptr, 0xF0, newlength); @@ -379,7 +379,7 @@ if (yield_length[store_pool] < STOREPOOL_MIN_SIZE && { b = b->next; #ifndef COMPILE_UTILITY - if (running_in_test_harness || debug_store) + if (debug_store) assert_no_variables(b, b->length + ALIGNED_SIZEOF_STOREBLOCK, filename, linenumber); #endif @@ -393,7 +393,7 @@ b->next = NULL; while ((b = bb)) { #ifndef COMPILE_UTILITY - if (running_in_test_harness || debug_store) + if (debug_store) assert_no_variables(b, b->length + ALIGNED_SIZEOF_STOREBLOCK, filename, linenumber); #endif @@ -411,7 +411,7 @@ linenumber = linenumber; #else DEBUG(D_memory) { - if (running_in_test_harness) + if (f.running_in_test_harness) debug_printf("---%d Rst ** %d\n", store_pool, pool_malloc); else debug_printf("---%d Rst %6p ** %-14s %4d %d\n", store_pool, ptr, @@ -428,14 +428,8 @@ DEBUG(D_memory) * Release store * ************************************************/ -/* This function is specifically provided for use when reading very -long strings, e.g. header lines. When the string gets longer than a -complete block, it gets copied to a new block. It is helpful to free -the old block iff the previous copy of the string is at its start, -and therefore the only thing in it. Otherwise, for very long strings, -dead store can pile up somewhat disastrously. This function checks that -the pointer it is given is the first thing in a block, and if so, -releases that block. +/* This function checks that the pointer it is given is the first thing in a +block, and if so, releases that block. Arguments: block block of store to consider @@ -445,17 +439,17 @@ Arguments: Returns: nothing */ -void -store_release_3(void *block, const char *filename, int linenumber) +static void +store_release_3(void * block, const char * filename, int linenumber) { -storeblock *b; +storeblock * b; /* It will never be the first block, so no need to check that. */ -for (b = chainbase[store_pool]; b != NULL; b = b->next) +for (b = chainbase[store_pool]; b; b = b->next) { - storeblock *bb = b->next; - if (bb != NULL && CS block == CS bb + ALIGNED_SIZEOF_STOREBLOCK) + storeblock * bb = b->next; + if (bb && CS block == CS bb + ALIGNED_SIZEOF_STOREBLOCK) { b->next = bb->next; pool_malloc -= bb->length + ALIGNED_SIZEOF_STOREBLOCK; @@ -463,21 +457,20 @@ for (b = chainbase[store_pool]; b != NULL; b = b->next) /* Cut out the debugging stuff for utilities, but stop picky compilers from giving warnings. */ - #ifdef COMPILE_UTILITY +#ifdef COMPILE_UTILITY filename = filename; linenumber = linenumber; - #else +#else DEBUG(D_memory) - { - if (running_in_test_harness) + if (f.running_in_test_harness) debug_printf("-Release %d\n", pool_malloc); else debug_printf("-Release %6p %-20s %4d %d\n", (void *)bb, filename, linenumber, pool_malloc); - } - if (running_in_test_harness) + + if (f.running_in_test_harness) memset(bb, 0xF0, bb->length+ALIGNED_SIZEOF_STOREBLOCK); - #endif /* COMPILE_UTILITY */ +#endif /* COMPILE_UTILITY */ free(bb); return; @@ -486,6 +479,43 @@ for (b = chainbase[store_pool]; b != NULL; b = b->next) } +/************************************************ +* Move store * +************************************************/ + +/* Allocate a new block big enough to expend to the given size and +copy the current data into it. Free the old one if possible. + +This function is specifically provided for use when reading very +long strings, e.g. header lines. When the string gets longer than a +complete block, it gets copied to a new block. It is helpful to free +the old block iff the previous copy of the string is at its start, +and therefore the only thing in it. Otherwise, for very long strings, +dead store can pile up somewhat disastrously. This function checks that +the pointer it is given is the first thing in a block, and that nothing +has been allocated since. If so, releases that block. + +Arguments: + block + newsize + len + +Returns: new location of data +*/ + +void * +store_newblock_3(void * block, int newsize, int len, + const char * filename, int linenumber) +{ +BOOL release_ok = store_last_get[store_pool] == block; +uschar * newtext = store_get(newsize); + +memcpy(newtext, block, len); +if (release_ok) store_release_3(block, filename, linenumber); +return (void *)newtext; +} + + /************************************************* @@ -528,7 +558,7 @@ linenumber = linenumber; /* If running in test harness, spend time making sure all the new store is not filled with zeros so as to catch problems. */ -if (running_in_test_harness) +if (f.running_in_test_harness) { memset(yield, 0xF0, (size_t)size); DEBUG(D_memory) debug_printf("--Malloc %5d %d %d\n", size, pool_malloc, @@ -568,7 +598,7 @@ linenumber = linenumber; #else DEBUG(D_memory) { - if (running_in_test_harness) + if (f.running_in_test_harness) debug_printf("----Free\n"); else debug_printf("----Free %6p %-20s %4d\n", block, filename, linenumber);