]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
lib/xz: fix XZ_DYNALLOC to avoid useless memory reallocations
authorLasse Collin <lasse.collin@tukaani.org>
Sat, 16 Nov 2019 01:34:39 +0000 (17:34 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 16 Nov 2019 02:34:00 +0000 (18:34 -0800)
s->dict.allocated was initialized to 0 but never set after a successful
allocation, thus the code always thought that the dictionary buffer has
to be reallocated.

Link: http://lkml.kernel.org/r/20191104185107.3b6330df@tukaani.org
Signed-off-by: Lasse Collin <lasse.collin@tukaani.org>
Reported-by: Yu Sun <yusun2@cisco.com>
Acked-by: Daniel Walker <danielwa@cisco.com>
Cc: "Yixia Si (yisi)" <yisi@cisco.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/xz/xz_dec_lzma2.c

index 08c3c804999831a2d658ada4366662da2f6a6311..156f26fdc4c91b6e502b8bee69b84e811911cac6 100644 (file)
@@ -1146,6 +1146,7 @@ XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s, uint8_t props)
 
                if (DEC_IS_DYNALLOC(s->dict.mode)) {
                        if (s->dict.allocated < s->dict.size) {
+                               s->dict.allocated = s->dict.size;
                                vfree(s->dict.buf);
                                s->dict.buf = vmalloc(s->dict.size);
                                if (s->dict.buf == NULL) {