From patchwork Mon Jun 29 20:17:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 6691691 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2F6E0C05AC for ; Mon, 29 Jun 2015 20:17:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7E263205D4 for ; Mon, 29 Jun 2015 20:17:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8E1BE205C6 for ; Mon, 29 Jun 2015 20:17:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752641AbbF2URJ (ORCPT ); Mon, 29 Jun 2015 16:17:09 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:34718 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752634AbbF2URI (ORCPT ); Mon, 29 Jun 2015 16:17:08 -0400 Received: from [10.172.65.212] (helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1Z9fUI-0004Kf-00; Mon, 29 Jun 2015 20:17:06 +0000 From: Colin King To: "Rafael J. Wysocki" , Len Brown , linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] ACPI / resources: fix memory leak on request_range fail path Date: Mon, 29 Jun 2015 21:17:00 +0100 Message-Id: <1435609020-18695-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 2.1.4 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Colin Ian King static analysis from cppcheck detected a memory leak: [drivers/acpi/resource.c:664]: (error) Memory leak: reg the error path on a failed request_range call should free reg before returning. Bug introduced in the recent commit 0f1b414d190724617eb1cdd615592fa8cd9d0b50 ("ACPI / PNP: Avoid conflicting resource reservations") Fixes: 0f1b414d19 ("ACPI / PNP: Avoid conflicting resource reservations") Signed-off-by: Colin Ian King --- drivers/acpi/resource.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c index fcb7807..10561ce 100644 --- a/drivers/acpi/resource.c +++ b/drivers/acpi/resource.c @@ -660,8 +660,10 @@ static int add_region_before(u64 start, u64 end, u8 space_id, return -ENOMEM; error = request_range(start, end, space_id, flags, desc); - if (error) + if (error) { + kfree(reg); return error; + } reg->start = start; reg->end = end;