From patchwork Wed Aug 7 09:08:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwen Wang X-Patchwork-Id: 11081783 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 4B61314F6 for ; Wed, 7 Aug 2019 09:47:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38E55285AF for ; Wed, 7 Aug 2019 09:47:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CC52289F1; Wed, 7 Aug 2019 09:47:29 +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 A55AE285AF for ; Wed, 7 Aug 2019 09: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 64D60826; Wed, 7 Aug 2019 11:09:18 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 64D60826 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1565169008; bh=bOr01533H49GHmEjsKvYso6wcIKHp9sCz+6J7ib9AJY=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=SeKEM/574UztI94vKLWCDJtwccFL2fPKiYzwoWY5R9uye+aZ1h9gZ4oJ4sab6f7R2 wZRTDyP6ZPL4IAceFVj8DTU98wztF4fK2ItpmrkvdAmKNEgbm7KAdUIbK3s4EkiedA FkE1suZhXIPalaRdSllc+sv07uEv2PsIfc4AYti8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id E7E51F80227; Wed, 7 Aug 2019 11:09:17 +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 7E1C6F80290; Wed, 7 Aug 2019 11:09:16 +0200 (CEST) Received: from mail-yw1-f68.google.com (mail-yw1-f68.google.com [209.85.161.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id CD41FF800E4 for ; Wed, 7 Aug 2019 11:09:13 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz CD41FF800E4 Received: by mail-yw1-f68.google.com with SMTP id z197so32044740ywd.13 for ; Wed, 07 Aug 2019 02:09:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=cYG9qyve6yyxmV+AOeRIzDv8dPpq2DUERiyZ5aq12Zs=; b=oxeGNgONZhkUgX5sENtjnV//zDSpklhuQCMb8G1T5vNxcuH0mzfF3Y27a6yPV3gbPp fhG00xicXm/B3CbsRtiV8dY2IOGsZDirNlRLX1/rZxkLuJ/gZb5f8UeWlp/iHkVBxeIy L4CIBJT7LZ5JqZHWhDHCEzWxonF/G2q6+0W6dKHQQNCynmlUcJGc9TjI3YzQod5aA8T5 VRuKsg4MLPjRjQxHXnIGZNymQDMkE4lCn88N/yefoHh43U17q0yfkA1f9ArrDA/FO1I2 rugasMBVs47ISI9WabtCQsmLbN+/irfwWJtOi4XNd6bbFbh7dokop8zOrtQWPj1/cy/C tHgA== X-Gm-Message-State: APjAAAXCJ+otsffvozHytjagTQBaz5leEw1cYHcF2eF1J/T3EaHj+9Dn ORcicT2ZOZhP78YeZeZs2uM= X-Google-Smtp-Source: APXvYqwNxPXEUwt4w+RyJ6UmqNqlXasDRygpmijmshd7FwsVJpuUzLPrT2DBiLP7P/OjcBZnCgqR0g== X-Received: by 2002:a81:47d5:: with SMTP id u204mr5374829ywa.145.1565168951718; Wed, 07 Aug 2019 02:09:11 -0700 (PDT) Received: from localhost.localdomain (24-158-240-219.dhcp.smyr.ga.charter.com. [24.158.240.219]) by smtp.gmail.com with ESMTPSA id 193sm369421ywh.89.2019.08.07.02.09.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Aug 2019 02:09:11 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Date: Wed, 7 Aug 2019 04:08:51 -0500 Message-Id: <1565168932-6337-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 Cc: "moderated list:SOUND" , open list , Greg Kroah-Hartman , Takashi Iwai , Thomas Gleixner , Allison Randal Subject: [alsa-devel] [PATCH v3] ALSA: hiface: 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: , MIME-Version: 1.0 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 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sound/usb/hiface/pcm.c b/sound/usb/hiface/pcm.c index 14fc1e1..c406497 100644 --- a/sound/usb/hiface/pcm.c +++ b/sound/usb/hiface/pcm.c @@ -600,14 +600,13 @@ int hiface_pcm_init(struct hiface_chip *chip, u8 extra_freq) ret = hiface_pcm_init_urb(&rt->out_urbs[i], chip, OUT_EP, hiface_pcm_out_urb_handler); if (ret < 0) - return ret; + goto error; } ret = snd_pcm_new(chip->card, "USB-SPDIF Audio", 0, 1, 0, &pcm); if (ret < 0) { - kfree(rt); dev_err(&chip->dev->dev, "Cannot create pcm instance\n"); - return ret; + goto error; } pcm->private_data = rt; @@ -620,4 +619,10 @@ int hiface_pcm_init(struct hiface_chip *chip, u8 extra_freq) chip->pcm = rt; return 0; + +error: + for (i = 0; i < PCM_N_URBS; i++) + kfree(rt->out_urbs[i].buffer); + kfree(rt); + return ret; }