[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] xz: fix XZ_DYNALLOC to avoid useless memory reallocations



commit 22d5d1c0d18893d9cb92b322f95d7ebab6c0cfd9
Author:     Lasse Collin <lasse.collin@xxxxxxxxxxx>
AuthorDate: Mon Mar 7 09:06:31 2022 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon Mar 7 09:06:31 2022 +0100

    xz: fix XZ_DYNALLOC to avoid useless memory reallocations
    
    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@xxxxxxxxxxx
    Reported-by: Yu Sun <yusun2@xxxxxxxxx>
    Signed-off-by: Lasse Collin <lasse.collin@xxxxxxxxxxx>
    Acked-by: Daniel Walker <danielwa@xxxxxxxxx>
    Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
    Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
8e20ba2e53fc
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Luca Fancellu <luca.fancellu@xxxxxxx>
    Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/common/xz/dec_lzma2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/xen/common/xz/dec_lzma2.c b/xen/common/xz/dec_lzma2.c
index 6b07722e3c..68bcf0f29a 100644
--- a/xen/common/xz/dec_lzma2.c
+++ b/xen/common/xz/dec_lzma2.c
@@ -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) {
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.