diff mbox series

[2/7] xz: fix XZ_DYNALLOC to avoid useless memory reallocations

Message ID 196008a7-ce37-52bf-13d3-4a08f203957a@suse.com (mailing list archive)
State Superseded
Headers show
Series (mainly) xz imports from Linux | expand

Commit Message

Jan Beulich Nov. 19, 2021, 10:21 a.m. UTC
From: Lasse Collin <lasse.collin@tukaani.org>

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>
[Linux commit: 8e20ba2e53fc6198cbfbcc700e9f884157052a8d]
Signed-off-by: Jan Beulich <jbeulich@suse.com>

Comments

Julien Grall Nov. 25, 2021, 4:55 p.m. UTC | #1
Hi Jan,

On 19/11/2021 10:21, Jan Beulich wrote:
> From: Lasse Collin <lasse.collin@tukaani.org>
> 
> 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>
> [Linux commit: 8e20ba2e53fc6198cbfbcc700e9f884157052a8d]

This commit contains two more signed-off-by. Any reason to not have 
included them here?

The rest of the patch LGTM.

> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> --- 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_lzma
>   
>   		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) {
> 

Cheers,
diff mbox series

Patch

--- 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_lzma
 
 		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) {