From patchwork Thu Aug 8 05:15:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwen Wang X-Patchwork-Id: 11083139 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 63B6F1709 for ; Thu, 8 Aug 2019 05:16:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F13928A50 for ; Thu, 8 Aug 2019 05:16:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4221C28A6B; Thu, 8 Aug 2019 05:16:37 +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 213EC28A50 for ; Thu, 8 Aug 2019 05:16:35 +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 1CBE8852; Thu, 8 Aug 2019 07:15:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1CBE8852 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1565241393; bh=/zfPyYFHd6SgFBNN2AEWhCnHLnkXgnENy6l5rYhB8wQ=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=CEIvVAvjaSL41sz3tyHlCa/veJMjKr9V2FTJhBe/NBJD5dk3MTGQHMIh9ZOmYYnml dPL8/hJtTzWHqH72Jkv0+Wtye+gg38b2FI9DY+8KrQy3fdrSo97UBuL8OrvdXz2+22 hA/zRzz0oIk8lYH1mj3r8wP4wBXHVU1Q4WcpybZ8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 8D104F804FF; Thu, 8 Aug 2019 07:15:42 +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 20B3DF80534; Thu, 8 Aug 2019 07:15:40 +0200 (CEST) Received: from mail-yw1-f67.google.com (mail-yw1-f67.google.com [209.85.161.67]) (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 63FDFF803F3 for ; Thu, 8 Aug 2019 07:15:36 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 63FDFF803F3 Received: by mail-yw1-f67.google.com with SMTP id g19so32810120ywe.2 for ; Wed, 07 Aug 2019 22:15:36 -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=Zqjm4Ms2LWPF2JxoVedKSLuooEVD3FC/Jr22qU9ttc0=; b=a1v1Ytx4Ubv3Fn7yzsKr3sHGa12eAXWg7ODy4Fp6Hqooutw+l7dVmBAjISYy/KuSmH sZTMgAs+LHjvop4xfXaWgRJu4QPksKaZPO+zQl0R9tn9f1iUbmb2X5m8vOvf1c/4Pvpu W6xpRnSC7r5N97igFiM964EdKKXkVXjVwjanJPsfR8WEcGDU2nWL9+/xWbKYlHFYRPw6 /E10HJyZ3BROcw+yHL6w3GQ+4lvmSo3m8UM2CLxhRsB4YmBYAxpxpaHoZkB6yhBndYdF JRB37kumLU6bYB6uHuX3jy+WmJQ/UsVdP71jh7gyt5s2E5ZVECid3z+K1R1pisYg2vEw sCpw== X-Gm-Message-State: APjAAAXgXRpwrKUhccQT0NGKuys2UgjXzk5MQdCOrGVy5PVAF2ijoCfE wenmf9VTO0HWywAX8fX74xQ= X-Google-Smtp-Source: APXvYqz08Zg+vgGovvm4k352MtWnv23Tf4vN81JusC7DQRnlND+8TfbEZkvXgCbk83qqGwiPPM57FA== X-Received: by 2002:a81:33cd:: with SMTP id z196mr7990265ywz.213.1565241335327; Wed, 07 Aug 2019 22:15:35 -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 v141sm20845902ywe.66.2019.08.07.22.15.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Aug 2019 22:15:34 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Date: Thu, 8 Aug 2019 00:15:21 -0500 Message-Id: <1565241321-2418-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 Cc: open list , "moderated list:SOUND" , Takashi Iwai Subject: [alsa-devel] [PATCH] sound: 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" X-Virus-Scanned: ClamAV using ClamSMTP In sound_insert_unit(), the controlling structure 's' is allocated through kmalloc(). Then it is added to the sound driver list by invoking __sound_insert_unit(). Later on, if __register_chrdev() fails, 's' is removed from the list through __sound_remove_unit(). If 'index' is not less than 0, -EBUSY is returned to indicate the error. However, 's' is not deallocated on this execution path, leading to a memory leak bug. To fix the above issue, free 's' before -EBUSY is returned. Signed-off-by: Wenwen Wang --- sound/sound_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sound/sound_core.c b/sound/sound_core.c index b730d97..90d118c 100644 --- a/sound/sound_core.c +++ b/sound/sound_core.c @@ -275,7 +275,8 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati goto retry; } spin_unlock(&sound_loader_lock); - return -EBUSY; + r = -EBUSY; + goto fail; } }