From patchwork Wed Aug 7 07:09:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwen Wang X-Patchwork-Id: 11081375 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE4B9912 for ; Wed, 7 Aug 2019 07:47:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC829287A8 for ; Wed, 7 Aug 2019 07:47:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0506287E9; Wed, 7 Aug 2019 07:47:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 14D35287A8 for ; Wed, 7 Aug 2019 07:47:26 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 478EC839; Wed, 7 Aug 2019 09:10:45 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 478EC839 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1565161895; bh=f/zeaHtWgo0fawG7amW05Bwa0kVx7EczHgyDJG0p5bc=; h=From:Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=h4+b5dptlcpvZGOXzUcMnq5kPp6XSV2/VGVX5pVKhxsEKsvvFNy0A8axdVJXPhDBK +vEUSW4RzmS+1itKS8ow7qWEOivugilqfym7uDwytazMGpT1Ci1ShN8mTEZaSlCsUH o/JBJ2mQ3vR6ZISeJFsKSG+7fh3dbE6z4x9dSniI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B19F7F80227; Wed, 7 Aug 2019 09:10:44 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 0E839F80290; Wed, 7 Aug 2019 09:10:43 +0200 (CEST) Received: from ajax.cs.uga.edu (ajax.cs.uga.edu [128.192.4.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 3ACF7F800F4 for ; Wed, 7 Aug 2019 09:10:39 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3ACF7F800F4 Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (authenticated bits=0) by ajax.cs.uga.edu (8.14.4/8.14.4) with ESMTP id x777Aapi061016 (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 7 Aug 2019 03:10:37 -0400 Received: by mail-lj1-f173.google.com with SMTP id z28so30238060ljn.4 for ; Wed, 07 Aug 2019 00:10:37 -0700 (PDT) X-Gm-Message-State: APjAAAUB1ISxWfnGGS6nEumcv7VKSska+RR4oxq6KXRgdWmsf9ewcpVB G79zTKeuPDMXJ2Pa388lhQN7Nkp4C5DAn9kgMjE= X-Google-Smtp-Source: APXvYqwTvZanyI0YZ9uQfaH1U+yBWhv+RJAwn5jJTqCGs8BDn7kVZC6l4H9aknl4nymRLzxWK49L4da/xdA1y1Rxk4s= X-Received: by 2002:a2e:8892:: with SMTP id k18mr4034234lji.239.1565161835957; Wed, 07 Aug 2019 00:10:35 -0700 (PDT) MIME-Version: 1.0 From: Wenwen Wang Date: Wed, 7 Aug 2019 03:09:59 -0400 X-Gmail-Original-Message-ID: Message-ID: To: Wenwen Wang Cc: "moderated list:SOUND" , open list , Greg Kroah-Hartman , Takashi Iwai , Thomas Gleixner , Allison Randal Subject: [alsa-devel] [PATCH v2] ALSA: pcm: fix multiple memory leak bugs X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" X-Virus-Scanned: ClamAV using ClamSMTP In hiface_pcm_init(), 'rt' is firstly allocated through kzalloc(). Later on, hiface_pcm_init_urb() is invoked to initialize 'rt->out_urbs[i]'. In hiface_pcm_init_urb(), 'rt->out_urbs[i].buffer' is allocated through kzalloc(). However, if hiface_pcm_init_urb() fails, both 'rt' and 'rt->out_urbs[i].buffer' are not deallocated, leading to memory leak bugs. Also, 'rt->out_urbs[i].buffer' is not deallocated if snd_pcm_new() fails. To fix the above issues, free 'rt' and 'rt->out_urbs[i].buffer'. Signed-off-by: Wenwen Wang --- sound/usb/hiface/pcm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) return ret; diff --git a/sound/usb/hiface/pcm.c b/sound/usb/hiface/pcm.c index 14fc1e1..9b132aa 100644 --- a/sound/usb/hiface/pcm.c +++ b/sound/usb/hiface/pcm.c @@ -599,12 +599,18 @@ int hiface_pcm_init(struct hiface_chip *chip, u8 extra_freq) for (i = 0; i < PCM_N_URBS; i++) { ret = hiface_pcm_init_urb(&rt->out_urbs[i], chip, OUT_EP, hiface_pcm_out_urb_handler); - if (ret < 0) + if (ret < 0) { + for (; i >= 0; i--) + kfree(rt->out_urbs[i].buffer); + kfree(rt); return ret; + } } ret = snd_pcm_new(chip->card, "USB-SPDIF Audio", 0, 1, 0, &pcm); if (ret < 0) { + for (i = 0; i < PCM_N_URBS; i++) + kfree(rt->out_urbs[i].buffer); kfree(rt); dev_err(&chip->dev->dev, "Cannot create pcm instance\n");