Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4180191ybx; Mon, 4 Nov 2019 09:04:30 -0800 (PST) X-Google-Smtp-Source: APXvYqxKa01vgYdUxmy7Dv3ZI9dBCCTkP+riNQFI/seblqlyOCnl/RBB04uHQC0qHBQpETWMmvSZ X-Received: by 2002:a50:f747:: with SMTP id j7mr20559488edn.247.1572887070019; Mon, 04 Nov 2019 09:04:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572887070; cv=none; d=google.com; s=arc-20160816; b=IxFJX7GfhPKXRa/0WSWKrEId2qj1r3UcbKs71O+Urcr9x3MHcQxpJHWT+q+TjnHADo Ri3KCpctcL+ISmvevgeNctD89iG/QWgwydytPkv5LwJVPJeiBYyITRRcCd3l/0PqtPY/ kh9G6VvbSlI8b2xPcTnZ9KKTwRI9XI4ELIfGOB2qcDask4SfZ6HKDIhumZAxShvAlkpz kpMdRlOsV/6UfUJGr+tdvVSSKFlRENtmXD+4CVdmnC8+l76y5CEI6u0eTHtGEWgXtTgQ yjZmtd38c3YGdeZq5jQcHIjJzpmPB3lo/F+el2k67pHJPtFev0B/pRPuwRFAbYQpg6Xw iHOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date; bh=41fV6449jjor/GRImKugGTqW/kHkWr+OiNmAxegZ30E=; b=uzKp6vI8suY9j06KNQ4gQTNGz6dwPZ4nR8ZBjRzmmiqZtkaoq4w5XU3MAAsX+fP3V+ L+ZjTeKqKryK7XknBKzPy67u6Z9Hpo/uD2Il6RaNci7O1Mh2Nh7UXhNGh7TKNYPfbO1n OYUO1DqdD+zgJzkRU1lN9XR8g88iYTXX/czu3lGEW+XcsGVwtn2r1iBeMhb7ds8J2eFr PxsIvbeo+wndT4IX23CvNQDgABim9Rt0qR3Gs8uu0uqLvqMbnhdMKu/T9YkQv8FmD0e0 fdaCuxBRDWGQo8XeAvKn7FiUPW+TN098UpaFxvKhZuDnKaP/qnkZC2Q12pIb3C9ODZJh DTPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b17si8027325edj.417.2019.11.04.09.04.06; Mon, 04 Nov 2019 09:04:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728888AbfKDRAc (ORCPT + 99 others); Mon, 4 Nov 2019 12:00:32 -0500 Received: from mailscanner02.zoner.fi ([84.34.166.11]:45024 "EHLO mailscanner02.zoner.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727998AbfKDRAc (ORCPT ); Mon, 4 Nov 2019 12:00:32 -0500 X-Greylist: delayed 553 seconds by postgrey-1.27 at vger.kernel.org; Mon, 04 Nov 2019 12:00:31 EST Received: from www25.zoner.fi (www25.zoner.fi [84.34.147.45]) by mailscanner02.zoner.fi (Postfix) with ESMTPS id 3464240AB9; Mon, 4 Nov 2019 18:51:12 +0200 (EET) Received: from mail.zoner.fi ([84.34.147.244]) by www25.zoner.fi with esmtp (Exim 4.92.3) (envelope-from ) id 1iRfZU-0003Ur-E0; Mon, 04 Nov 2019 18:51:16 +0200 Date: Mon, 4 Nov 2019 18:51:07 +0200 From: Lasse Collin To: Andrew Morton Cc: linux-kernel@vger.kernel.org, "Yu Sun (yusun2)" , "Yixia Si (yisi)" Subject: [PATCH] lib/xz: Fix XZ_DYNALLOC to avoid useless memory reallocations Message-ID: <20191104185107.3b6330df@tukaani.org> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lasse Collin 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 Reported-by: Yu Sun --- 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) {