]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: chunks: allocate the trash chunks before parsing the config
authorWilly Tarreau <w@1wt.eu>
Fri, 13 Dec 2013 13:41:10 +0000 (14:41 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 13 Dec 2013 13:41:10 +0000 (14:41 +0100)
get_trash_chunk() is convenient also while parsing the config, better
allocate them early just like the global trash.

src/cfgparse.c
src/chunk.c
src/haproxy.c

index 0a39d22577ca8a132048374df066edec82d79cd9..579dbcc530a7d7e915d9ab3ea5b1e81c1cc7013e 100644 (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) {
index 9463abb28e6b864f250c046c9dbb8447d71fb4c5..f84ab10510e04954104a1b7787af7af5d6bd15c4 100644 (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;
 }
 
index 86d1899983ac2709074a6c6338521300a44bf51c..0ec217e534b2aeda41494a82a9dbd21b46b1ee3a 100644 (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));