[2/2] lib/xz: Fix XZ_DYNALLOC to avoid useless memory reallocations.
diff mbox series

Message ID 20191108200040.20259-2-danielwa@cisco.com
State New, archived
Headers show
Series
  • [1/2] fs/squashfs: Make SquashFS xz initialization mode configurable
Related show

Commit Message

Daniel Walker Nov. 8, 2019, 8 p.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.

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

Signed-off-by: Yu Sun <yusun2@cisco.com>
Cc: xe-linux-external@cisco.com
Signed-off-by: Daniel Walker <dwalker@fifo99.com>
---
 lib/xz/xz_dec_lzma2.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Daniel Walker Nov. 8, 2019, 8:27 p.m. UTC | #1
On Fri, Nov 08, 2019 at 12:00:40PM -0800, Daniel Walker 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.
> 
> For the original commit to xz-embedded.git, please refer to:
> https://git.tukaani.org/?p=xz-embedded.git;a=commit;h=40d291b
> 
> Signed-off-by: Yu Sun <yusun2@cisco.com>


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
Andrew Morton Nov. 8, 2019, 8:50 p.m. UTC | #2
On Fri, 8 Nov 2019 12:27:54 -0800 Daniel Walker <danielwa@cisco.com> wrote:

> On Fri, Nov 08, 2019 at 12:00:40PM -0800, Daniel Walker 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.
> > 
> > For the original commit to xz-embedded.git, please refer to:
> > https://git.tukaani.org/?p=xz-embedded.git;a=commit;h=40d291b
> > 
> > Signed-off-by: Yu Sun <yusun2@cisco.com>
> 
> 
> 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 ;)

Patch
diff mbox series

diff --git a/lib/xz/xz_dec_lzma2.c b/lib/xz/xz_dec_lzma2.c
index 08c3c8049998..156f26fdc4c9 100644
--- a/lib/xz/xz_dec_lzma2.c
+++ b/lib/xz/xz_dec_lzma2.c
@@ -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) {