From patchwork Tue Jan 7 15:18:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Fries X-Patchwork-Id: 11321041 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB23114B4 for ; Tue, 7 Jan 2020 15:20:03 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 766DF24656 for ; Tue, 7 Jan 2020 15:20:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="WoxRbilW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 766DF24656 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=Fries.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 4CF031849; Tue, 7 Jan 2020 16:19:09 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4CF031849 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1578410399; bh=JLucXqHN/Kv6ofqc+R6OxsYGJ6tZjj6MNwZC5P+Yg84=; h=Date:From:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=WoxRbilWcY8yZoCY+n2/xJlhdLO82TjYxv4A0Kwpu+lGhT6ka27fP5W4fcLuEpUeM 0LKCsRhbd3ArjoVypK64SI2wGmfMvx8WjosTi7WQsUs5UDTh5A25Or80Tt+hOihLSv GP0wWVKbl4n/FmqAKm+NqXsN1qZr6Kzg/3NE9yw0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id A5152F8010D; Tue, 7 Jan 2020 16:18:23 +0100 (CET) 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 E391AF801F5; Tue, 7 Jan 2020 16:18:20 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_NONE,SPF_PASS, SURBL_BLOCKED,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from SpacedOut.fries.net (SpacedOut.fries.net [IPv6:2001:470:3832:200::1]) (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 AEC09F80140 for ; Tue, 7 Jan 2020 16:18:17 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz AEC09F80140 Received: from SpacedOut.fries.net (ip6-localhost [IPv6:0:0:0:0:0:0:0:1]) by SpacedOut.fries.net (8.15.2/8.15.2/Debian-8) with ESMTPS id 007FIAkP009408 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 7 Jan 2020 09:18:10 -0600 Received: (from david@localhost) by SpacedOut.fries.net (8.15.2/8.15.2/Submit) id 007FIAnL009407; Tue, 7 Jan 2020 09:18:10 -0600 Date: Tue, 7 Jan 2020 09:18:10 -0600 From: David Fries To: alsa-devel@alsa-project.org Message-ID: <20200107151810.pzthoz3w2y3wqae7@spacedout.fries.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.5.11 (SpacedOut.fries.net [IPv6:::1]); Tue, 07 Jan 2020 09:18:10 -0600 (CST) Cc: Takashi Iwai Subject: [alsa-devel] [PATCH] mixer: Fix memory leak for more than 16 file descriptor case 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" Signed-off-by: David Fries Reviewed-by: Takashi Iwai --- Added signed off. I saw this when digging through the source code, wrote up a test case, and verified with valgrind. I don't have that many sound cards so I modified mixer.c to always take the conditional. alloca seemed like the least effort way to fix this. Other thoughts were to test pfds != spfds and free, but given how little bytes would be allocated putting on the stack seems reasonable. I also created the github pull request 20. https://github.com/alsa-project/alsa-lib/pull/20 src/mixer/mixer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mixer/mixer.c b/src/mixer/mixer.c index 82056474..b1af9945 100644 --- a/src/mixer/mixer.c +++ b/src/mixer/mixer.c @@ -767,7 +767,7 @@ int snd_mixer_wait(snd_mixer_t *mixer, int timeout) if (count < 0) return count; if ((unsigned int) count > sizeof(spfds) / sizeof(spfds[0])) { - pfds = malloc(count * sizeof(*pfds)); + pfds = alloca(count * sizeof(*pfds)); if (!pfds) return -ENOMEM; err = snd_mixer_poll_descriptors(mixer, pfds,