Skip to contentSkip to conversation

lib/xz: Fix XZ_DYNALLOC to avoid useless memory reallocations.

PATCH In review Daniel Walker 2 participants 3 messages Nov 8, 2019 Xz embedded

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 lib/xz: Fix XZ_DYNALLOC to avoid useless memory reallocations.

From: Lasse Collin <[email protected]>

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.

For the original commit to xz-embedded.git, please refer to:
https://git.tukaani.org/?p=xz-embedded.git;a=commit;h=40d291b

---
 lib/xz/xz_dec_lzma2.c | 1 +
 1 file changed, 1 insertion(+)
lib/xz/xz_dec_lzma2.c +1 -0
index 08c3c8049998..156f26fdc4c9 100644
@@ -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) {
Signature · 1 line
2.17.1
#1 lore raw
Quoted 10 lines · Daniel Walker

From: Lasse Collin <[email protected]>

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.

For the original commit to xz-embedded.git, please refer to:
https://git.tukaani.org/?p=xz-embedded.git;a=commit;h=40d291b

Yu made me aware that Lasse had sent this on Nov. 4. I would recommend you take that patch, and disregard this one. Cisco is using it and we would like to see it merged.

Daniel

#2 lore raw
Quoted 10 lines · On Fri, 8 Nov 2019 12:27:54 -0800 Daniel Walker <[email protected]> wrote:
Quoted 9 lines · Daniel Walker

From: Lasse Collin <[email protected]>

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.

For the original commit to xz-embedded.git, please refer to:
https://git.tukaani.org/?p=xz-embedded.git;a=commit;h=40d291b

Quoted 6 lines
Quoted 1 line

Yu made me aware that Lasse had sent this on Nov. 4. I would recommend you take that patch, and disregard this one. Cisco is using it and we would like to see it merged.

No probs. I'll take that as an acked-by ;)