Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp251162yba; Mon, 20 May 2019 08:08:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkZx5VG+JoscGyhoytJSep+1G9MV/JDYzSrEqNiGxsBslboYJx2NKEZaags0u1AyPcGp5k X-Received: by 2002:a62:128a:: with SMTP id 10mr79974063pfs.225.1558364895464; Mon, 20 May 2019 08:08:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558364895; cv=none; d=google.com; s=arc-20160816; b=it6OnFfVfOVHaDqS3sxnv4psXi/cE5yVcLF8KOcOyoGB1oHXcEdYKzinvaqFtCgXaJ 9aCQq1XUqYghAbNweC3UaWxwmO482MoFubkCOw9TzD3dIr97D6zR1fZvWDIz80BJOmGs 6+QJvcHxvkjkATsNAzqeik5QMHPYm+GaN8nqLkNhL0H19G88sxWfFtnarYxp4C8SJwtu bS9YvuhYmK9Ldq673BRZGX1qRjYULJTu/QTdC6x2qlJ3CJSWMpjmKZoyuD4B8tn5fihu 1dJ+Y6qWPsXUW/zz6MOs+nASIUYH+5NucShOYgztOdsfHeuJxlea3spZyf/b+HqQZdw3 yoNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=988INtZ/6gNMIhWx3rjLzt4cVoUy6/Ztoi69YWD/H5c=; b=ggvSSXPM+3Qt1gDaHx6d41RiXg30ol2L3cYlj/ou3qHLekNDuluv8TZMdjDUIBT6wO oaN5WXe6DYqx5wujhwR+RanwMDyltnXjHzjJrAtUMI2HylUm/sT88WxITtsSerhrfCc9 MHAXZ7rkaQGekq4N8TfuNqz9eHhiWPW53l8eGRP/Q2WULanxEo7zjYOYxfzJMGxQY+zS jwpIpM0TryhnScjP690x7ApbhIX1gwhPic6cPgN3oaIltc/RMKtPUvRDyJbmUbe/Yj3D +VGsU7i/RBJmgaE7zqD8UswnxP/H1shub+vgO7oPLAAHt8W24TTy3HD1jmobIuzFw9ev p2cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JWbJx1bN; 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 ay3si16824855plb.298.2019.05.20.08.07.59; Mon, 20 May 2019 08:08:15 -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; dkim=pass header.i=@kernel.org header.s=default header.b=JWbJx1bN; 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 S2388388AbfETMWU (ORCPT + 99 others); Mon, 20 May 2019 08:22:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:36296 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388374AbfETMWS (ORCPT ); Mon, 20 May 2019 08:22:18 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9215521019; Mon, 20 May 2019 12:22:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558354938; bh=53VozYmXf1eG5m7OkSRjT5xXTRtlW1k3WYIKOmwy+oA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JWbJx1bN4kYHl9zmfB5rgAc4PjYUfcH/jsnTiDQ2ZIyjlYSuHrQJYJjigUbHaVScd X/TlPYJZ45IdSzmOnfEpWfsrVQS+B4UuuWMcNoVhp1LvRcIzZuxmQ3NXP8ZFONEW38 k+SdJcWyxpoVDB5RSiKXieOQRTEOKKVm3/I8SZUI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenwen Wang , Takashi Iwai Subject: [PATCH 4.19 034/105] ALSA: usb-audio: Fix a memory leak bug Date: Mon, 20 May 2019 14:13:40 +0200 Message-Id: <20190520115249.402736691@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wenwen Wang commit cb5173594d50c72b7bfa14113dfc5084b4d2f726 upstream. In parse_audio_selector_unit(), the string array 'namelist' is allocated through kmalloc_array(), and each string pointer in this array, i.e., 'namelist[]', is allocated through kmalloc() in the following for loop. Then, a control instance 'kctl' is created by invoking snd_ctl_new1(). If an error occurs during the creation process, the string array 'namelist', including all string pointers in the array 'namelist[]', should be freed, before the error code ENOMEM is returned. However, the current code does not free 'namelist[]', resulting in memory leaks. To fix the above issue, free all string pointers 'namelist[]' in a loop. Signed-off-by: Wenwen Wang Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/usb/mixer.c | 2 ++ 1 file changed, 2 insertions(+) --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -2679,6 +2679,8 @@ static int parse_audio_selector_unit(str kctl = snd_ctl_new1(&mixer_selectunit_ctl, cval); if (! kctl) { usb_audio_err(state->chip, "cannot malloc kcontrol\n"); + for (i = 0; i < desc->bNrInPins; i++) + kfree(namelist[i]); kfree(namelist); kfree(cval); return -ENOMEM;