Skip to contentSkip to conversation

lib/xz: Fix XZ_DYNALLOC to avoid useless memory reallocations

PATCH New Lasse Collin 1 participant 1 message Nov 4, 2019 Xz embedded

lore
Share & tools
lore

Lasse Collin

author maintainer
#0 lore raw

PATCH 1/1 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.

---

lib/xz/xz_dec_lzma2.c +1 -0
diff -Nrup linux-5.3-vanilla/lib/xz/xz_dec_lzma2.c linux-5.3/lib/xz/xz_dec_lzma2.c
@@ -1146,6 +1146,7 @@ XZ_EXTERN enum xz_ret xz_dec_lzma2_reset
 
 		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) {