]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
xz: fix XZ_DYNALLOC to avoid useless memory reallocations
authorLasse Collin <lasse.collin@tukaani.org>
Mon, 7 Mar 2022 08:06:31 +0000 (09:06 +0100)
committerJan Beulich <jbeulich@suse.com>
Mon, 7 Mar 2022 08:06:31 +0000 (09:06 +0100)
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
Reported-by: Yu Sun <yusun2@cisco.com>
Signed-off-by: Lasse Collin <lasse.collin@tukaani.org>
Acked-by: Daniel Walker <danielwa@cisco.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 8e20ba2e53fc
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/common/xz/dec_lzma2.c

index 6b07722e3cea6961d72e70e1b6a3ea70c61527aa..68bcf0f29a132465e072bc958c177b3039978c7e 100644 (file)
@@ -1146,6 +1146,7 @@ XZ_EXTERN enum xz_ret __init xz_dec_lzma2_reset(struct xz_dec_lzma2 *s, uint8_t
 
                if (DEC_IS_DYNALLOC(s->dict.mode)) {
                        if (s->dict.allocated < s->dict.size) {
+                               s->dict.allocated = s->dict.size;
                                large_free(s->dict.buf);
                                s->dict.buf = large_malloc(s->dict.size);
                                if (s->dict.buf == NULL) {