MINOR: chunks: allocate the trash chunks before parsing the config

get_trash_chunk() is convenient also while parsing the config, better
allocate them early just like the global trash.
This commit is contained in:
Willy Tarreau 2013-12-13 14:41:10 +01:00
parent 5f3f15f618
commit 2819e99417
3 changed files with 7 additions and 4 deletions

View File

@ -609,6 +609,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
if (global.tune.maxrewrite >= global.tune.bufsize / 2)
global.tune.maxrewrite = global.tune.bufsize / 2;
chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize);
alloc_trash_buffers(global.tune.bufsize);
}
else if (!strcmp(args[0], "tune.maxrewrite")) {
if (*(args[1]) == 0) {

View File

@ -51,12 +51,14 @@ struct chunk *get_trash_chunk(void)
return trash_chunk;
}
/* Allocates the trash buffers. Returns 0 in case of failure. */
/* (re)allocates the trash buffers. Returns 0 in case of failure. It is
* possible to call this function multiple times if the trash size changes.
*/
int alloc_trash_buffers(int bufsize)
{
trash_size = bufsize;
trash_buf1 = (char *)calloc(1, bufsize);
trash_buf2 = (char *)calloc(1, bufsize);
trash_buf1 = (char *)realloc(trash_buf1, bufsize);
trash_buf2 = (char *)realloc(trash_buf2, bufsize);
return trash_buf1 && trash_buf2;
}

View File

@ -491,6 +491,7 @@ void init(int argc, char **argv)
struct tm curtime;
chunk_init(&trash, malloc(global.tune.bufsize), global.tune.bufsize);
alloc_trash_buffers(global.tune.bufsize);
/* NB: POSIX does not make it mandatory for gethostname() to NULL-terminate
* the string in case of truncation, and at least FreeBSD appears not to do
@ -817,7 +818,6 @@ void init(int argc, char **argv)
swap_buffer = (char *)calloc(1, global.tune.bufsize);
get_http_auth_buff = (char *)calloc(1, global.tune.bufsize);
static_table_key = calloc(1, sizeof(*static_table_key) + global.tune.bufsize);
alloc_trash_buffers(global.tune.bufsize);
fdinfo = (struct fdinfo *)calloc(1,
sizeof(struct fdinfo) * (global.maxsock));