linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lasse Collin <lasse.collin@tukaani.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
	"Yu Sun (yusun2)" <yusun2@cisco.com>,
	"Yixia Si (yisi)" <yisi@cisco.com>
Subject: [PATCH] lib/xz: Fix XZ_DYNALLOC to avoid useless memory reallocations
Date: Mon, 4 Nov 2019 18:51:07 +0200	[thread overview]
Message-ID: <20191104185107.3b6330df@tukaani.org> (raw)

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.

Signed-off-by: Lasse Collin <lasse.collin@tukaani.org>
Reported-by: Yu Sun <yusun2@cisco.com>
---

diff -Nrup linux-5.3-vanilla/lib/xz/xz_dec_lzma2.c linux-5.3/lib/xz/xz_dec_lzma2.c
--- linux-5.3-vanilla/lib/xz/xz_dec_lzma2.c	2019-09-16 00:19:32.000000000 +0300
+++ linux-5.3/lib/xz/xz_dec_lzma2.c	2019-10-30 20:33:15.460857851 +0200
@@ -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) {

                 reply	other threads:[~2019-11-04 17:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191104185107.3b6330df@tukaani.org \
    --to=lasse.collin@tukaani.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yisi@cisco.com \
    --cc=yusun2@cisco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).