Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2FE1C433F5 for ; Sat, 20 Nov 2021 07:19:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236709AbhKTHLt (ORCPT ); Sat, 20 Nov 2021 02:11:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236602AbhKTHLo (ORCPT ); Sat, 20 Nov 2021 02:11:44 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8474AC061574 for ; Fri, 19 Nov 2021 23:08:40 -0800 (PST) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[127.0.0.1]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1moKUF-0004ad-GU; Sat, 20 Nov 2021 08:08:36 +0100 From: Ahmad Fatoum Subject: Re: [PATCH] Fixup: perf bench: Fix two memory leaks detected with ASan To: Sohaib Mohamed , jolsa@redhat.com Cc: acme@kernel.org, irogers@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, namhyung@kernel.org, songliubraving@fb.com References: <20211120040854.95169-1-sohaib.amhmd@gmail.com> <0c4189c4-3788-0fef-fce0-3527ec90b4b1@pengutronix.de> Message-ID: Date: Sat, 20 Nov 2021 08:08:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <0c4189c4-3788-0fef-fce0-3527ec90b4b1@pengutronix.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: a.fatoum@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20.11.21 07:53, Ahmad Fatoum wrote: >> + snd_ctx_arr[total_counter] = snd_ctx; > > You are storing at snd_ctx_arr[num_fd] each time, so you will leak > all context, except for the last one. Oh, it's more subtle than that. total_counter is of course incremented every time in the previous loop, so you will have num_fd times NULL (from static initialization) then a pointer to an allocation and so on. That works by the looks of it, but looks quite strange. -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |