Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5088838ybh; Wed, 7 Aug 2019 00:11:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzaCagRqBuwK6R+rjGSwsIpRNxJ009D8b9DipIYr5dDpVdsGNF6ckPAcuSjj1T0rn3YZywq X-Received: by 2002:a17:902:24b:: with SMTP id 69mr6588937plc.250.1565161906190; Wed, 07 Aug 2019 00:11:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565161906; cv=none; d=google.com; s=arc-20160816; b=nnvelnZPXaxPeP5kCVe/pf9XPdVdOm4Jqj3ZhcUiyQtK7aIRylcCMqok2wmf8ah05+ HR2Czq1DN/ZfYVqXKsZt7SLiFpattDr11QBC7su4F3NYWpZRGU3fb3YYTc0W8uvPcWdY ras5jGCMb40ipRUAdUpgtHB4/EMSgI18unPnnzmUowB5/Gpe2j29D5cxVfwbkYq0Oo2I um5/CLMDIypvjivpnbNSZmduFv9Al9nB6f3z7pxzICnJ2MR9K4QYOVUCF3KhNEARfE2B 8s4b42BRRy2WG7WEkaBOgD87QkNnqQ6RXBNzQ7rX85JTNlXqL+zzFFS+LNAnLhB6IOfv Rerw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :mime-version; bh=Areak9+lBspA/+RqCHdvtvQ23vnzX11/7IylN0/SOp8=; b=o+7CUKNCny95ImWTBb3NCgYTCQeYZuhX8rSdrUjs+UPXeGDh/6v7ICcJtbBuqfw3Or HBMDKW6BMehM/IZy7EATFW1vY5IPyku72cjVKC55pFCidHnerSaKyjvSq7/DIqQMf7fY v4OdCep8944jQaN9dtpfQozVshsl4C7kvGpDtWLcujrPSmvHauLVVLIbeb32HRwQi5L+ RKciW2FADSochKU1d1uJ62ghgtDvvMJOK191ytvekpb3hp6OIJAOZEWfDEvdkkx4jwF2 bbf0d4BqzdwBlTxcOC5Nw6gMeo1suXvrPc0cv6BAQbgHA7BM/A/cWJ5O8K7oL5STqgeh ZXfg== 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 h1si36280410pgd.443.2019.08.07.00.11.30; Wed, 07 Aug 2019 00:11:46 -0700 (PDT) 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 S1728360AbfHGHKj (ORCPT + 99 others); Wed, 7 Aug 2019 03:10:39 -0400 Received: from ajax.cs.uga.edu ([128.192.4.6]:45264 "EHLO ajax.cs.uga.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727914AbfHGHKj (ORCPT ); Wed, 7 Aug 2019 03:10:39 -0400 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (authenticated bits=0) by ajax.cs.uga.edu (8.14.4/8.14.4) with ESMTP id x777AajM061015 (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 7 Aug 2019 03:10:37 -0400 Received: by mail-lj1-f179.google.com with SMTP id t28so84456541lje.9 for ; Wed, 07 Aug 2019 00:10:37 -0700 (PDT) X-Gm-Message-State: APjAAAVXiswFLtgrBOM7Cr9rOrI/6JBvC8YDNlN5tAGH0wbv+se3XcRS nZNHktfKJeOMjitHOPLolfOZx/UbCtnBnpcGUgk= 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: Subject: [PATCH v2] ALSA: pcm: fix multiple memory leak bugs To: Wenwen Wang Cc: Jaroslav Kysela , Takashi Iwai , Allison Randal , Thomas Gleixner , Greg Kroah-Hartman , "moderated list:SOUND" , open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) 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"); return ret; -- 2.7.4