Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5057869ybh; Tue, 6 Aug 2019 23:38:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+OpL74dZ8EcXWHf0Y2lthbn0h0yPSZmCgBp45mBhY9fF/Ku7P68YwrrAEjrnIA2hSu/cE X-Received: by 2002:a17:90a:d996:: with SMTP id d22mr6967106pjv.86.1565159913034; Tue, 06 Aug 2019 23:38:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565159913; cv=none; d=google.com; s=arc-20160816; b=vwXGIz1Nk+dpKTajefQxNxk6rNNHBESiLfjxPJCcLKxFb10nqBzzuKMiZxX0kOeQoi iSYHjG649XaC2n6OsNOVCLFWJjZrdK+7YExf3dBxuYZOCHCEdWGkjLy238b1KuFIfZcQ 7srF3j7HerP151oduO5RNbOiMaK9HBPFuN6etH0OjoeOWspFnyUtmHo9VgmTRXWnbFKt DNp0JXfIP9jFXBtJ+UW4MhXFlZ+Nc6Qu836KI1Rc3Nkx+XUm0/fzf61qRtKjItsEGOcc 2Nvc5oMeRdz4h6SfT0CT5VO5ghPe1r/RnJwE57FABs44IUKUF4yko3rFbEV1RMWFQRvZ wudQ== 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 :in-reply-to:references:mime-version; bh=S7fMlrSqVky1Z+B9L8J3NaBQzl7dFSLgPBrRqIAOKDg=; b=c/PGLdulaN+RnYFkNArFfHAD9MySFHzg+7CyMyOjztk5byc6RmqHFeEBunm9CEo0wy thX7vdc9QggksR6I1WHxAzUL9/i9pFwbkOLiDRv/ijPA8fkMh/2sUd25xLHWUPIUOw1W lOZJpjTJoHcjaaGuDfLbdiePhTWenHGHV/J99WM0O9wA/b0LLc58P8Gl4ald3d424EmN U0oXtuw9EEdeFbFffqseaHfi12W4+vnu81sZ1imVlObUAWf5P2wip/UN7bMWKCxsnA+N 8wCZWeevIQYESNHQVDtvggg/aUF39SC+Qj35nwXGAM56tCPDDEkhOvdceVxNjQSp0Ee1 8ouQ== 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 c22si43856257plz.361.2019.08.06.23.38.16; Tue, 06 Aug 2019 23:38:33 -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 S1727272AbfHGGg1 (ORCPT + 99 others); Wed, 7 Aug 2019 02:36:27 -0400 Received: from ajax.cs.uga.edu ([128.192.4.6]:44940 "EHLO ajax.cs.uga.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727051AbfHGGg1 (ORCPT ); Wed, 7 Aug 2019 02:36:27 -0400 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (authenticated bits=0) by ajax.cs.uga.edu (8.14.4/8.14.4) with ESMTP id x776aPfp060234 (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 7 Aug 2019 02:36:26 -0400 Received: by mail-lf1-f43.google.com with SMTP id x3so63264847lfc.0 for ; Tue, 06 Aug 2019 23:36:26 -0700 (PDT) X-Gm-Message-State: APjAAAUCAfC/ne2th2s4qQ0AnSsdS7sDdz8IJUlgsNULd+Spic5YtDN8 cA/JNHKtSo38vByC4P4csSMKa1TOQyP2h0vDJ5M= X-Received: by 2002:a19:4aca:: with SMTP id x193mr4878607lfa.146.1565159785183; Tue, 06 Aug 2019 23:36:25 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Wenwen Wang Date: Wed, 7 Aug 2019 02:35:49 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] ALSA: pcm: fix a memory leak bug To: Takashi Iwai Cc: "moderated list:SOUND" , Thomas Gleixner , Greg Kroah-Hartman , Allison Randal , Jaroslav Kysela , Takashi Iwai , open list , Wenwen Wang 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 On Wed, Aug 7, 2019 at 2:33 AM Takashi Iwai wrote: > > On Wed, 07 Aug 2019 08:15:17 +0200, > Wenwen Wang wrote: > > > > In hiface_pcm_init(), 'rt' is firstly allocated through kzalloc(). Later > > on, hiface_pcm_init_urb() is invoked to initialize 'rt->out_urbs[i]'. > > However, if the initialization fails, 'rt' is not deallocated, leading to a > > memory leak bug. > > > > To fix the above issue, free 'rt' before returning the error. > > > > Signed-off-by: Wenwen Wang > > --- > > sound/usb/hiface/pcm.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/sound/usb/hiface/pcm.c b/sound/usb/hiface/pcm.c > > index 14fc1e1..5dbcd0d 100644 > > --- a/sound/usb/hiface/pcm.c > > +++ b/sound/usb/hiface/pcm.c > > @@ -599,8 +599,10 @@ 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) { > > + kfree(rt); > > return ret; > > + } > > Unfortunately this still leaves some memory. We need to release > rt->out_urbs[], too. The relevant code is already in > hiface_pcm_destroy(), so factor out the looped kfree() there and call > it from both places. > > Care to resubmit with more fixes? Thanks for your comments! I also found this issue, and am working on another patch to fix it. Wenwen