]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
cgfs: make dorealloc allocate the first batch, too
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 8 Jan 2016 20:16:16 +0000 (12:16 -0800)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Fri, 8 Jan 2016 20:16:16 +0000 (12:16 -0800)
With a short first line the case can be
 *mem = NULL
 oldlen = 0
 newlen = 5 (anything < 50)
making newbatches == oldbatches == 1 causing the
 (newbatches <= oldbatches)
condition to be true.

Let realloc() handle *mem==NULL and use
(!*mem || newbatches > oldbatches) as the only condition.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
cgfs.c

diff --git a/cgfs.c b/cgfs.c
index 1f31ed13f98970a434f4014d6dd7f0e922321763..e6330e3668b2c4f0d50f891bf86b8c6867cb91ba 100644 (file)
--- a/cgfs.c
+++ b/cgfs.c
@@ -77,14 +77,7 @@ static void dorealloc(char **mem, size_t oldlen, size_t newlen)
        int newbatches = (newlen / BATCH_SIZE) + 1;
        int oldbatches = (oldlen / BATCH_SIZE) + 1;
 
-       if (newbatches <= oldbatches)
-               return;
-
-       if (!*mem) {
-               do {
-                       *mem = malloc(newbatches * BATCH_SIZE);
-               } while (!*mem);
-       } else {
+       if (!*mem || newbatches > oldbatches) {
                char *tmp;
                do {
                        tmp = realloc(*mem, newbatches * BATCH_SIZE);