Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5188937ybh; Wed, 7 Aug 2019 02:10:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBsvMuLtASKZvbgfuA8XqLR0TAuOSPg6HO1I8/9RboeMdks/JipczazZAjnsVxyEmbzcn/ X-Received: by 2002:a17:902:8f93:: with SMTP id z19mr6972797plo.97.1565169025000; Wed, 07 Aug 2019 02:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565169024; cv=none; d=google.com; s=arc-20160816; b=YvfUQzqwm4tVgDVUYi3v1utnMQJe02IRYmaYExPHFnTSLGyyCeNJyc0+iICIhLBdUF pSnXKGP8cZ4TTGZ9i0mSl+N+EUr96oaIPeuDwBjnxIGok73xLlQsYmg9sgw0Q9QKkoMs BgzOySB6sCwEXwdRxVHBUvArr3REtm+o8qL12UApzeUwbv6Awkcnt0yvLq9XTRdx57vN e6TZNNeSnyK4X5DQq0SzzUPwHLFqoV7DpdE4CNT1h2dXrWj7jLrwrpPxdIhJ8LjPF+Ym AKDaCa5FaT2TVlaR/9vqIj0NhMA5BkeZE/v354YKEmR4HZk33xxhQTqF26RXlH0I27Ry xj0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=cYG9qyve6yyxmV+AOeRIzDv8dPpq2DUERiyZ5aq12Zs=; b=aSvZ9T78peMKafyg5FbZeEATp8Rqyy3ewppUdj1z23vsY73dQtsXcCbLtl27xKiqRk dqUbdqsyvFTQw6QGkaOL8KMvaYqeLP5Hn6pAmMDZVI5PdFfM+4KsGO6rNDEK60NQ8dGK vaZ40ZHeTLRJIrnGAXmQMd5gmmo1R5Qc3pft/nmFkK1q5ElrfVYM3XSKPG3s6xgpyD5R jaIa5lRAhgWzdM2uMC49nP5mM7tieam/GzfmXI4g+ZgoF7XlUq7V6x+UKmIl8RljtO0l bfq3u6UEfA+GWwyqGJxTYBEmI/DwG9Oysm/WUMiqaqIHp2TpGruJiEBf7E2UcGdVD+ET JAGQ== 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 o2si7585754pgc.349.2019.08.07.02.10.08; Wed, 07 Aug 2019 02:10:24 -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 S1727753AbfHGJJM (ORCPT + 99 others); Wed, 7 Aug 2019 05:09:12 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:37792 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726244AbfHGJJM (ORCPT ); Wed, 7 Aug 2019 05:09:12 -0400 Received: by mail-yw1-f67.google.com with SMTP id u141so32062658ywe.4 for ; Wed, 07 Aug 2019 02:09:12 -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=cYG9qyve6yyxmV+AOeRIzDv8dPpq2DUERiyZ5aq12Zs=; b=SKUZRpOVwQ5AJTF4pNeoHjGAH0DH0tWhObE/Z2r75vnr1z0YSUCOdOxJsVj4tyNtsC oVyKF9WI8Wnt30tcwHnoESftooaL1OSgnTQCzDtgEHDFR07LWpVks78EQdYgV1hiQaQ8 uJVpII/jr5hg6Kh9Z6WP/6/KKehvo5EXWdZ6C4V4VsZadJTIO+8IxGvzHg8huk6VXKas //HOfUvrfhGVbjsECpaTmlscyUxH3BzdJC66Gj8z0DuavoLtB+vTVnkf76UAdRA99HIh +xstTCKnLYkwb9cjP9DsH0AnObetUa9ps1yl5BULXYajm014OjFIQsCUtPap+LIWyZWs 782A== X-Gm-Message-State: APjAAAWDRKL88/K6eii+E0Er9zQf/r9f1xrPouCRjonIlbuO4ihxST3u eN0OL2lCTaaSSh/EMKKhBNk= X-Received: by 2002:a81:47d5:: with SMTP id u204mr5374829ywa.145.1565168951718; Wed, 07 Aug 2019 02:09:11 -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 193sm369421ywh.89.2019.08.07.02.09.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Aug 2019 02:09:11 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Jaroslav Kysela , Takashi Iwai , Allison Randal , Thomas Gleixner , Greg Kroah-Hartman , alsa-devel@alsa-project.org (moderated list:SOUND), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3] ALSA: hiface: fix multiple memory leak bugs Date: Wed, 7 Aug 2019 04:08:51 -0500 Message-Id: <1565168932-6337-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In hiface_pcm_init(), 'rt' is firstly allocated through kzalloc(). Later on, hiface_pcm_init_urb() is invoked to initialize 'rt->out_urbs[i]'. In hiface_pcm_init_urb(), 'rt->out_urbs[i].buffer' is allocated through kzalloc(). However, if hiface_pcm_init_urb() fails, both 'rt' and 'rt->out_urbs[i].buffer' are not deallocated, leading to memory leak bugs. Also, 'rt->out_urbs[i].buffer' is not deallocated if snd_pcm_new() fails. To fix the above issues, free 'rt' and 'rt->out_urbs[i].buffer'. Signed-off-by: Wenwen Wang --- sound/usb/hiface/pcm.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sound/usb/hiface/pcm.c b/sound/usb/hiface/pcm.c index 14fc1e1..c406497 100644 --- a/sound/usb/hiface/pcm.c +++ b/sound/usb/hiface/pcm.c @@ -600,14 +600,13 @@ int hiface_pcm_init(struct hiface_chip *chip, u8 extra_freq) ret = hiface_pcm_init_urb(&rt->out_urbs[i], chip, OUT_EP, hiface_pcm_out_urb_handler); if (ret < 0) - return ret; + goto error; } ret = snd_pcm_new(chip->card, "USB-SPDIF Audio", 0, 1, 0, &pcm); if (ret < 0) { - kfree(rt); dev_err(&chip->dev->dev, "Cannot create pcm instance\n"); - return ret; + goto error; } pcm->private_data = rt; @@ -620,4 +619,10 @@ int hiface_pcm_init(struct hiface_chip *chip, u8 extra_freq) chip->pcm = rt; return 0; + +error: + for (i = 0; i < PCM_N_URBS; i++) + kfree(rt->out_urbs[i].buffer); + kfree(rt); + return ret; } -- 2.7.4