Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3667310ybh; Mon, 5 Aug 2019 23:14:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYvUknrnkOlXVoqq2GiINSE8tGLfuibiopwRUQs7okKwIS3FvB+rHugGWnaMfDjsHAExpK X-Received: by 2002:aa7:940c:: with SMTP id x12mr2025896pfo.80.1565072083127; Mon, 05 Aug 2019 23:14:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565072083; cv=none; d=google.com; s=arc-20160816; b=fhcV2yKHTtmnvCIADi0mbNkebFhjAjP/VaxlQsgB6f8ExpWrmt95T1LRQH3fiiwaHU uChAEYHdjSwJM+jACROCkv//hvmJBlnwP/PjjbdyzE532D2sJ2H1tq1Qqksew8SXJQD4 rP1uVIyBidZH+mmcJ+ZH5huDykxpzPTEo5txOfmNsZdQ8d88BmzKzmrY7B8NTxYl0IbD B0fpKOfQ+9SrML94Km74U0sNqsM8SYcBIDsZhovYB0+s7zoBPHLrkAz3jbqoREQUAFNk 7zbwnCM/gA1Nj8FAwA0Jcbz8vpnQ55YJPsKlDpk/9qWPDaRJgzj2MYtSyhNz+8lN2irL U4tw== 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 :mime-version; bh=oRKvnAEn6ryu+r5XjK2MZwSmpuYPjcg9GkCVisVu2rI=; b=CR4lfyvEi702NojmiCqF+wuwtXvfzmx0qrAISDP0CHvhgYWwQ4x+RH9ch/Qf1nL8jE sKt6RErIDCaC+uQitfK/fnIUTwpme1esPKT/iTtwoWquMEvEv6ypmUOPaX409wDUwdqK +kDolNrdhVjvPsQycO09Bmar76LtBy4BGTtVXNzF5N+nKYbjvKdGR23K9Fyecnrje3vY 2u8Mw/3FS5qQQfYJPE8J1HAeCBOoiFN88YbcFHbzNHmNNfLsFEgsOmdB71Xt16GL/7hl ZXh/6G6Y4Uw5H1pARiH/gq32Dhdims9/PVZ6GmNgrK83SuJca3Th5wCzRnGjJZx8k2UO hA3Q== 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 l10si49747342pgp.411.2019.08.05.23.14.27; Mon, 05 Aug 2019 23:14:43 -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 S1731756AbfHFGNr (ORCPT + 99 others); Tue, 6 Aug 2019 02:13:47 -0400 Received: from ajax.cs.uga.edu ([128.192.4.6]:59080 "EHLO ajax.cs.uga.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731560AbfHFGNr (ORCPT ); Tue, 6 Aug 2019 02:13:47 -0400 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (authenticated bits=0) by ajax.cs.uga.edu (8.14.4/8.14.4) with ESMTP id x766DgjQ031603 (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 6 Aug 2019 02:13:43 -0400 Received: by mail-lf1-f51.google.com with SMTP id h28so59983994lfj.5 for ; Mon, 05 Aug 2019 23:13:43 -0700 (PDT) X-Gm-Message-State: APjAAAWCs/i8dkY2hNBACdw7brQNDQ4PknQ9d/zrqBoQJZ23rCLsdbvA 58LiUm0WmqBONmXDeAUaFOqWWQacOKQunNkQhiw= 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: Subject: [PATCH] ALSA: usb-audio: fix a memory leak bug To: Wenwen Wang Cc: Jaroslav Kysela , Takashi Iwai , Kate Stewart , Greg Kroah-Hartman , Richard Fontana , Allison Randal , Thomas Gleixner , "moderated list:SOUND" , open list 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 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(-) 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; -- 2.7.4