diff --git a/src/cfgparse.c b/src/cfgparse.c index 0a39d2257..579dbcc53 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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) { diff --git a/src/chunk.c b/src/chunk.c index 9463abb28..f84ab1051 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -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; } diff --git a/src/haproxy.c b/src/haproxy.c index 86d189998..0ec217e53 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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));