[lxc-devel] [PATCH lxcfs 4/5] cgfs: fix dorealloc's batch allocation
Serge Hallyn
serge.hallyn at ubuntu.com
Thu Jan 7 18:42:54 UTC 2016
Quoting Wolfgang Bumiller (w.bumiller at proxmox.com):
> The initial check should use real lengths as with modulo a
> new required length of eg. 52 would be considered smaller
> than an old length of 48 (2 < 48).
>
> To get the 'batches' count 'newlen' must be divided and not
> taken modulo BATCH_SIZE. Otherwise '101', which would need a
> 3rd batch to reach 150, would end up with two (2*50 = 100
> bytes) and thereby be truncated instead.
>
> Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
> ---
> cgfs.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/cgfs.c b/cgfs.c
> index 0659e9e..681a478 100644
> --- a/cgfs.c
> +++ b/cgfs.c
> @@ -75,9 +75,9 @@ static inline void drop_trailing_newlines(char *s)
> static void dorealloc(char **mem, size_t oldlen, size_t newlen)
> {
> int batches;
> - if (newlen % BATCH_SIZE <= oldlen % BATCH_SIZE)
> + if (newlen <= oldlen)
This will result in extra reallocs (though innocuous).
Is there any reason not to just do
if (newlen / BATCH_SIZE <= oldlen / BATCH_SIZE)
> return;
> - batches = (newlen % BATCH_SIZE) + 1;
> + batches = (newlen / BATCH_SIZE) + 1;
> if (!*mem) {
> do {
> *mem = malloc(batches * BATCH_SIZE);
> --
> 2.1.4
>
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
More information about the lxc-devel
mailing list