From patchwork Tue Aug 6 06:13:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwen Wang X-Patchwork-Id: 11078789 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 78965112C for ; Tue, 6 Aug 2019 12:47:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61374288DA for ; Tue, 6 Aug 2019 12:47:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 554CA2892B; Tue, 6 Aug 2019 12:47:28 +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 AF452288DA for ; Tue, 6 Aug 2019 12:47:22 +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 AF6721663; Tue, 6 Aug 2019 08:47:38 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz AF6721663 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1565074108; bh=A7VSNbEExivFyKm+mh6ijyzR6wrurGgFZ7CaI3YEKfw=; h=From:Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=vTwy5PsNltXcnQfiL9Rk8LbLy7SDOIZBMyc5VzXTpWDMQoT32gtpCs3fjLrW5a6Jd FjIM3QaHX2kpmFqo4vCqO9ZU+2z30ZuaKtsB/BKOe7x1BDHWZwEehkWmtSst3+JtTT ClopEvYaQlXMoUuMs7arXzYITOyUA9IEnSxjt0DM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 89D82F80533; Tue, 6 Aug 2019 08:46:43 +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 E5044F80483; Tue, 6 Aug 2019 08:13:50 +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 12013F8011B for ; Tue, 6 Aug 2019 08:13:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 12013F8011B Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (authenticated bits=0) by ajax.cs.uga.edu (8.14.4/8.14.4) with ESMTP id x766DgGd031607 (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 6 Aug 2019 02:13:44 -0400 Received: by mail-lf1-f53.google.com with SMTP id 62so55163019lfa.8 for ; Mon, 05 Aug 2019 23:13:43 -0700 (PDT) X-Gm-Message-State: APjAAAXjg4Fzw+CEpBlOoYXY7pdmqcdSfvwYdm6omz9xPmqZAhbOjt37 jZkjV/q8elBPXJc4VAyuX/QSs3U9YLNAVBJDuk8= X-Google-Smtp-Source: APXvYqw1rV8RcMwhWvkw7ZNGJnFRxEGT7QjoZpw//yMfjk/vN5bfurliBHT9CDnOIGrD5vrZ4HS7tCa02o/2rRsOax0= X-Received: by 2002:ac2:48b8:: with SMTP id u24mr1134365lfg.170.1565072022191; Mon, 05 Aug 2019 23:13:42 -0700 (PDT) MIME-Version: 1.0 From: Wenwen Wang Date: Tue, 6 Aug 2019 02:13:06 -0400 X-Gmail-Original-Message-ID: Message-ID: To: Wenwen Wang X-Mailman-Approved-At: Tue, 06 Aug 2019 08:46:41 +0200 Cc: Kate Stewart , "moderated list:SOUND" , open list , Greg Kroah-Hartman , Takashi Iwai , Richard Fontana , Thomas Gleixner , Allison Randal Subject: [alsa-devel] [PATCH] ALSA: usb-audio: fix a memory leak bug 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 add_new_ctl(), a mixer element structure is allocated through kzalloc() and the pointer is saved to 'elem'. Later on, a new alsa control element is created and added to this structure. In case the add process fails, i.e., the return value of snd_usb_mixer_add_control() is less than 0, the allocated structure is not freed, leading to a memory leak. To fix the above issue, free 'elem' before returning the error. Signed-off-by: Wenwen Wang --- sound/usb/mixer_scarlett.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/sound/usb/mixer_scarlett.c b/sound/usb/mixer_scarlett.c index 83715fd..a6c028a 100644 --- a/sound/usb/mixer_scarlett.c +++ b/sound/usb/mixer_scarlett.c @@ -562,8 +562,10 @@ static int add_new_ctl(struct usb_mixer_interface *mixer, strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); err = snd_usb_mixer_add_control(&elem->head, kctl); - if (err < 0) + if (err < 0) { + kfree(elem); return err; + } if (elem_ret) *elem_ret = elem;