From patchwork Thu Mar 14 15:10:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10853081 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7DB8F1669 for ; Thu, 14 Mar 2019 15:10:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A57D2A0A7 for ; Thu, 14 Mar 2019 15:10:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6908F2A30B; Thu, 14 Mar 2019 15:10:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 215F52A34B for ; Thu, 14 Mar 2019 15:10:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727139AbfCNPKq (ORCPT ); Thu, 14 Mar 2019 11:10:46 -0400 Received: from mail-pf1-f169.google.com ([209.85.210.169]:37870 "EHLO mail-pf1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726360AbfCNPKp (ORCPT ); Thu, 14 Mar 2019 11:10:45 -0400 Received: by mail-pf1-f169.google.com with SMTP id 8so621171pfr.4 for ; Thu, 14 Mar 2019 08:10:45 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=hcirEjwUJgEEtaMfUBUC6GWeKcLAiAjHfhiUllCOh+s=; b=MB2H0q+geQMRgUAeV81vFeP4Gr8MLU1EHrd5o4EMmYPr+bcOROzN9Hv6sAk8ivm1xV jL68oOmgWJxmrH1RbMedfwFWwQKAUIS4+X6532uSccw0EImwbtNbV9AlcV5MG7dwF1YG Tu7IH/SiNO3VGamlvHoWiJuB8us8K6oqBd12Rz/mdf9lbAJKU7iEoJzrmWvxQ+G5EtiC QD2TC38AMpVnz80Ll7ByJ7fUOFswerCuKtB8lxPxRZkQ/W07LkPODXgd/9mJcnH+IVXd 79olyskRgBFGdL5mJ6ML2/48frA75V/wbekGfeFHlxIGT2n5hC04IPNfC9ipLSkojERl HmNg== X-Gm-Message-State: APjAAAXM8YnPXsB/RS70c9tMeSFniJXSfVspYRzOWn9GuVn9EeWY1jOx TF9ZSfn5e7i0TbBxHeRsL6rTg4jh X-Google-Smtp-Source: APXvYqx4DFCE4SBtHJxQEJzAtC7iA9ubrAkiwY+7yqUYCLIWte3CSAsPS09cuMdzwffOISQoUHFS2A== X-Received: by 2002:a63:4e4e:: with SMTP id o14mr4641314pgl.254.1552576245107; Thu, 14 Mar 2019 08:10:45 -0700 (PDT) Received: from mamba.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id f65sm8165585pfg.98.2019.03.14.08.10.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2019 08:10:44 -0700 (PDT) From: Yordan Karadzhov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 08/12] kernel-shark: Fix memory leak in KsPlotget::getTaskColorTable() Date: Thu, 14 Mar 2019 17:10:08 +0200 Message-Id: <20190314151012.905-9-ykaradzhov@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190314151012.905-1-ykaradzhov@vmware.com> References: <20190314151012.905-1-ykaradzhov@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The std::vector constructor used here makes a copy of the data, so the memory used by the original array has to be freed. This is a major leak because getTaskColorTable() gets called every time when we redraw the plots. BTW calling getTaskColorTable() every time when we redraw makes no sense. This will be fixed in the following patch. Signed-off-by: Yordan Karadzhov --- kernel-shark/src/KsPlotTools.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel-shark/src/KsPlotTools.cpp b/kernel-shark/src/KsPlotTools.cpp index d07f414..2b16a51 100644 --- a/kernel-shark/src/KsPlotTools.cpp +++ b/kernel-shark/src/KsPlotTools.cpp @@ -122,6 +122,8 @@ ColorTable getTaskColorTable() std::vector temp_pids(pids, pids + nTasks); std::sort(temp_pids.begin(), temp_pids.end()); + free(pids); + if (temp_pids[i] == 0) { /* The "Idle" process (pid = 0) will be plotted in black. */ colors[i++] = {};