From patchwork Thu May 23 15:09:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10957945 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 0849E924 for ; Thu, 23 May 2019 15:10:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E47902855C for ; Thu, 23 May 2019 15:10:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D86F52867C; Thu, 23 May 2019 15:10:05 +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 7D3542855C for ; Thu, 23 May 2019 15:10:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730757AbfEWPKF (ORCPT ); Thu, 23 May 2019 11:10:05 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43362 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730672AbfEWPKF (ORCPT ); Thu, 23 May 2019 11:10:05 -0400 Received: by mail-wr1-f67.google.com with SMTP id t7so6383870wrr.10 for ; Thu, 23 May 2019 08:10:04 -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=gi7GVk1HqwO6+Be3ftO4ZXNXJHlwD24wE0aCW1RAME4=; b=Bk/QCTNwVm3aYf5CStGWg/7MWwGdRjjgCYALvvD+SSSG1iNhmVlhJjPhc+eQBlzMiy Wi8US0GtdES2dkN3RkYVw7ZYmlE+bmZ60Drfq6Hidfa2JUGwcXfCCJ8mLq/cGoOfHlAf QeMXcSdvPgIbim11L+1zK67jCgq7qf8uoh6XyKVvm4c2dAncKWCdop2GKMw0cSksnFvL bs5K9c9Jc0UjhBNqpV7GWGMoTcVvdgwN2k+rUmt1/nXDkJr5pnjGQLwx+QAik2J4lx15 cfXHNQ2s/GppD4dNvdmMu0Bap262+fexT9Obj3kVV7YLKt+7/flsQ0Wn6MSRd9SKVbrZ USfA== X-Gm-Message-State: APjAAAWF7q2BwuhKFSPF2oKCagkgd87yH4jqtzSCoFAZzIORB2Wg2YZX qP6HSIQ5wc+YKwXBhzWZ+nM= X-Google-Smtp-Source: APXvYqwygODwgAu1ZA1e7SNBpuFFVWpZUXWCXfX37H34G0HURO0LM76en5y8YTaMU3BjYhR4kr/ixw== X-Received: by 2002:a5d:4d92:: with SMTP id b18mr59544533wru.212.1558624203730; Thu, 23 May 2019 08:10:03 -0700 (PDT) Received: from mamba.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id k63sm10721996wmf.35.2019.05.23.08.10.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 08:10:03 -0700 (PDT) From: Yordan Karadzhov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, y.karadz@gmail.com, Yordan Karadzhov Subject: [PATCH 1/3] kernel-shark: Add Doxygen documentation for KsGLWidget::update() Date: Thu, 23 May 2019 18:09:44 +0300 Message-Id: <20190523150946.30769-2-ykaradzhov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523150946.30769-1-ykaradzhov@vmware.com> References: <20190523150946.30769-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 No functional changes in this patch. Signed-off-by: Yordan Karadzhov --- kernel-shark/src/KsGLWidget.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel-shark/src/KsGLWidget.hpp b/kernel-shark/src/KsGLWidget.hpp index 82831cf..e141b0a 100644 --- a/kernel-shark/src/KsGLWidget.hpp +++ b/kernel-shark/src/KsGLWidget.hpp @@ -41,6 +41,7 @@ public: void reset(); + /** Reprocess all graphs. */ void update() {resizeGL(width(), height());} void mousePressEvent(QMouseEvent *event); From patchwork Thu May 23 15:09:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10957947 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 2765815A6 for ; Thu, 23 May 2019 15:10:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1056A26E3E for ; Thu, 23 May 2019 15:10:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02802284A5; Thu, 23 May 2019 15:10:07 +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 5C56D26E3E for ; Thu, 23 May 2019 15:10:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730829AbfEWPKH (ORCPT ); Thu, 23 May 2019 11:10:07 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34599 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730672AbfEWPKH (ORCPT ); Thu, 23 May 2019 11:10:07 -0400 Received: by mail-wr1-f67.google.com with SMTP id f8so6716359wrt.1 for ; Thu, 23 May 2019 08:10:05 -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=XWZrADjqmO8GGNZryUluJSS1DKCO4GWML2KP6hlMCHY=; b=OfoqwdZ2UZbePEuXQ5QD+X5VeVdD/Rp5hLUqZeLiHhfgNVDCf4iZeZNcyff5lnil2E MTmr8lQJMyPbfSkZ0lkMOAZqv7vG8n52suiML9c6IGvjbW7+o7To5iPBb/2B2BsdpArO E3FAlQFwgAtxGU/dZLVjUhvC8XaSqWdzGhQDXKversOXwLyxmq3BOw1ScjhthdyYfwrJ rj1VkQG5YRT+l8asix+IJNJUUwmXXKsqS10SyneQr4gWtzgXYcHvb9oFGOBM1ueHCjel ic1gGexdc3ohF9qQPD08Ly4+I0uShQSHd92yt4IjxHuycF4EIw1w5OmFNfQlglbJXRa1 71DQ== X-Gm-Message-State: APjAAAU8Kq3tDZAq/chz6pifDhCDc5yiIQMW3tgLbXcDrqRyAUi4InAN j5WStVzo6NPVLut/AAck5jm3SWuM X-Google-Smtp-Source: APXvYqzibnotQfmhiQW3dXehmlvO7/ckV3JSqN3FzgJESMHv1kChZOSAUumvSAO+PeLR/KQGfspwjQ== X-Received: by 2002:a05:6000:11c8:: with SMTP id i8mr3044460wrx.175.1558624205138; Thu, 23 May 2019 08:10:05 -0700 (PDT) Received: from mamba.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id k63sm10721996wmf.35.2019.05.23.08.10.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 08:10:04 -0700 (PDT) From: Yordan Karadzhov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, y.karadz@gmail.com, Yordan Karadzhov Subject: [PATCH 2/3] kernel-shark: Handle properly the negative error codes when loading data Date: Thu, 23 May 2019 18:09:45 +0300 Message-Id: <20190523150946.30769-3-ykaradzhov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523150946.30769-1-ykaradzhov@vmware.com> References: <20190523150946.30769-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 get_records() can return negative error codes. This means that we alway have to use signed integer types for the "data size" variables / fields. Signed-off-by: Yordan Karadzhov --- kernel-shark/examples/datafilter.c | 6 +++++- kernel-shark/examples/datahisto.c | 6 +++++- kernel-shark/examples/dataload.c | 6 +++++- kernel-shark/src/KsMainWindow.cpp | 9 ++++----- kernel-shark/src/KsUtils.cpp | 6 +++--- kernel-shark/src/KsUtils.hpp | 4 ++-- kernel-shark/src/libkshark.c | 13 +++++++------ 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/kernel-shark/examples/datafilter.c b/kernel-shark/examples/datafilter.c index 688e581..bebc181 100644 --- a/kernel-shark/examples/datafilter.c +++ b/kernel-shark/examples/datafilter.c @@ -15,7 +15,7 @@ const char *default_file = "trace.dat"; int main(int argc, char **argv) { - size_t i, n_rows, n_tasks, n_evts, count; + ssize_t i, n_rows, n_tasks, n_evts, count; struct kshark_context *kshark_ctx; struct kshark_entry **data = NULL; struct tep_event_filter *adv_filter; @@ -42,6 +42,10 @@ int main(int argc, char **argv) /* Load the content of the file into an array of entries. */ n_rows = kshark_load_data_entries(kshark_ctx, &data); + if (n_rows < 1) { + kshark_free(kshark_ctx); + return 1; + } /* Filter the trace data coming from trace-cmd. */ n_tasks = kshark_get_task_pids(kshark_ctx, &pids); diff --git a/kernel-shark/examples/datahisto.c b/kernel-shark/examples/datahisto.c index 99ac495..02c6285 100644 --- a/kernel-shark/examples/datahisto.c +++ b/kernel-shark/examples/datahisto.c @@ -80,7 +80,7 @@ int main(int argc, char **argv) struct kshark_context *kshark_ctx; struct kshark_entry **data = NULL; struct kshark_trace_histo histo; - size_t i, n_rows, n_tasks; + ssize_t i, n_rows, n_tasks; bool status; int *pids; @@ -102,6 +102,10 @@ int main(int argc, char **argv) /* Load the content of the file into an array of entries. */ n_rows = kshark_load_data_entries(kshark_ctx, &data); + if (n_rows < 1) { + kshark_free(kshark_ctx); + return 1; + } /* Get a list of all tasks. */ n_tasks = kshark_get_task_pids(kshark_ctx, &pids); diff --git a/kernel-shark/examples/dataload.c b/kernel-shark/examples/dataload.c index 0cbc0f6..15c5de0 100644 --- a/kernel-shark/examples/dataload.c +++ b/kernel-shark/examples/dataload.c @@ -17,7 +17,7 @@ int main(int argc, char **argv) { struct kshark_context *kshark_ctx; struct kshark_entry **data = NULL; - size_t r, n_rows, n_tasks; + ssize_t r, n_rows, n_tasks; char *entry_str; bool status; int *pids; @@ -40,6 +40,10 @@ int main(int argc, char **argv) /* Load the content of the file into an array of entries. */ n_rows = kshark_load_data_entries(kshark_ctx, &data); + if (n_rows < 1) { + kshark_free(kshark_ctx); + return 1; + } /* Print to the screen the list of all tasks. */ n_tasks = kshark_get_task_pids(kshark_ctx, &pids); diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp index c7c7f6b..1e03632 100644 --- a/kernel-shark/src/KsMainWindow.cpp +++ b/kernel-shark/src/KsMainWindow.cpp @@ -515,7 +515,7 @@ void KsMainWindow::_importFilter() kshark_config_doc *conf; QString fileName; - if (!kshark_instance(&kshark_ctx)) + if (!kshark_instance(&kshark_ctx) || _data.size() < 1) return; fileName = KsUtils::getFile(this, "Import Filter", @@ -995,11 +995,10 @@ void KsMainWindow::loadDataFile(const QString& fileName) tload.join(); - if (!_data.size()) { - QString text("File "); + if (_data.size() < 1) { + QString text("No data was loaded from file "); - text.append(fileName); - text.append(" contains no data."); + text.append(fileName + "."); _error(text, "loadDataErr2", true, true); return; diff --git a/kernel-shark/src/KsUtils.cpp b/kernel-shark/src/KsUtils.cpp index dcedd7b..58ce8c1 100644 --- a/kernel-shark/src/KsUtils.cpp +++ b/kernel-shark/src/KsUtils.cpp @@ -306,14 +306,14 @@ void KsDataStore::loadDataFile(const QString &file) void KsDataStore::_freeData() { - if (_dataSize) { - for (size_t r = 0; r < _dataSize; ++r) + if (_dataSize > 0) { + for (ssize_t r = 0; r < _dataSize; ++r) free(_rows[r]); free(_rows); - _rows = nullptr; } + _rows = nullptr; _dataSize = 0; } diff --git a/kernel-shark/src/KsUtils.hpp b/kernel-shark/src/KsUtils.hpp index b4663da..7362c14 100644 --- a/kernel-shark/src/KsUtils.hpp +++ b/kernel-shark/src/KsUtils.hpp @@ -161,7 +161,7 @@ public: struct kshark_entry **rows() const {return _rows;} /** Get the size of the data array. */ - size_t size() const {return _dataSize;} + ssize_t size() const {return _dataSize;} void reload(); @@ -198,7 +198,7 @@ private: struct kshark_entry **_rows; /** The size of the data array. */ - size_t _dataSize; + ssize_t _dataSize; void _freeData(); void _unregisterCPUCollections(); diff --git a/kernel-shark/src/libkshark.c b/kernel-shark/src/libkshark.c index 654aaa9..b0018f8 100644 --- a/kernel-shark/src/libkshark.c +++ b/kernel-shark/src/libkshark.c @@ -680,8 +680,8 @@ static void free_rec_list(struct rec_list **rec_list, int n_cpus, free(rec_list); } -static size_t get_records(struct kshark_context *kshark_ctx, - struct rec_list ***rec_list, enum rec_type type) +static ssize_t get_records(struct kshark_context *kshark_ctx, + struct rec_list ***rec_list, enum rec_type type) { struct kshark_event_handler *evt_handler; struct tep_event_filter *adv_filter; @@ -851,12 +851,12 @@ static int pick_next_cpu(struct rec_list **rec_list, int n_cpus, * negative error code on failure. */ ssize_t kshark_load_data_entries(struct kshark_context *kshark_ctx, - struct kshark_entry ***data_rows) + struct kshark_entry ***data_rows) { struct kshark_entry **rows; struct rec_list **rec_list; enum rec_type type = REC_ENTRY; - size_t count, total = 0; + ssize_t count, total = 0; int n_cpus; if (*data_rows) @@ -895,6 +895,7 @@ ssize_t kshark_load_data_entries(struct kshark_context *kshark_ctx, free(rows[count]); } free(rows); + fail: fprintf(stderr, "Failed to allocate memory during data loading.\n"); return -ENOMEM; @@ -913,14 +914,14 @@ ssize_t kshark_load_data_entries(struct kshark_context *kshark_ctx, * negative error code on failure. */ ssize_t kshark_load_data_records(struct kshark_context *kshark_ctx, - struct tep_record ***data_rows) + struct tep_record ***data_rows) { struct tep_record **rows; struct tep_record *rec; struct rec_list **rec_list; struct rec_list *temp_rec; enum rec_type type = REC_RECORD; - size_t count, total = 0; + ssize_t count, total = 0; int n_cpus; total = get_records(kshark_ctx, &rec_list, REC_RECORD); From patchwork Thu May 23 15:09:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10957951 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 27E8D924 for ; Thu, 23 May 2019 15:10:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12EF526E79 for ; Thu, 23 May 2019 15:10:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07A062855C; Thu, 23 May 2019 15:10:10 +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 D535E26E79 for ; Thu, 23 May 2019 15:10:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730672AbfEWPKI (ORCPT ); Thu, 23 May 2019 11:10:08 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39017 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730756AbfEWPKI (ORCPT ); Thu, 23 May 2019 11:10:08 -0400 Received: by mail-wm1-f67.google.com with SMTP id z23so2103761wma.4 for ; Thu, 23 May 2019 08:10:07 -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=UsHaSwSYqaEfZCjR8nTLFDCgOG8KHp7nw1/cLADerdA=; b=R7ltQqcJzf7RXokKGxg+iLJKCnNliYsDPeKV6hrFRWioKHltbPmK70KHA++s7kt9aq YkdSRaXffqXw3BjCx9mbUVw2GsVJVnz8GhhJD5+URvshP/GR3BYFl9FWC8UIjW7Rn53a jQeazI+plWhpPmF/Ts/COUV0rYKm6dLw4W6lR2/1scScD+Iv6V4c7/VZOVY7nhHxuJYj GOkEC3l7hrD6VdJMcO60RA8rxG5t1L7bgX21Dkj5stHiZo+JTItoF3HCcSRz1ni6TqAW eicBuQMGd8QtmBQEg2nbkBOgLAmyUkiFQ+bEr2nlTTvMESiVQjKVRiuBej9aUEEyy3Mj 9fjA== X-Gm-Message-State: APjAAAUHcC+lH6yB+xBLgdDu1RFgKJdDDeJ4EubJj9NCf7h2DBToRg1+ aPF0Lmk2X2YoerRlx18yyC8= X-Google-Smtp-Source: APXvYqy2hD3Rdql+5tGVQNXhKRbcu6lPWnhOwhByZvy8r7VjY2GPZFzxE/vLAOexBKNgM91zigl1Mw== X-Received: by 2002:a1c:9a14:: with SMTP id c20mr12925861wme.61.1558624206436; Thu, 23 May 2019 08:10:06 -0700 (PDT) Received: from mamba.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id k63sm10721996wmf.35.2019.05.23.08.10.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 08:10:06 -0700 (PDT) From: Yordan Karadzhov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, y.karadz@gmail.com, Yordan Karadzhov Subject: [PATCH 3/3] kernel-shark: Correct memory management when data loading fails Date: Thu, 23 May 2019 18:09:46 +0300 Message-Id: <20190523150946.30769-4-ykaradzhov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523150946.30769-1-ykaradzhov@vmware.com> References: <20190523150946.30769-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 erroneous case, when the memory allocation failed during data loading, hasn't been properly handled. Signed-off-by: Yordan Karadzhov --- kernel-shark/src/libkshark.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/kernel-shark/src/libkshark.c b/kernel-shark/src/libkshark.c index b0018f8..175279c 100644 --- a/kernel-shark/src/libkshark.c +++ b/kernel-shark/src/libkshark.c @@ -889,12 +889,6 @@ ssize_t kshark_load_data_entries(struct kshark_context *kshark_ctx, fail_free: free_rec_list(rec_list, n_cpus, type); - for (count = 0; count < total; count++) { - if (!rows[count]) - break; - free(rows[count]); - } - free(rows); fail: fprintf(stderr, "Failed to allocate memory during data loading.\n"); @@ -924,15 +918,15 @@ ssize_t kshark_load_data_records(struct kshark_context *kshark_ctx, ssize_t count, total = 0; int n_cpus; - total = get_records(kshark_ctx, &rec_list, REC_RECORD); + total = get_records(kshark_ctx, &rec_list, type); if (total < 0) goto fail; + n_cpus = tracecmd_cpus(kshark_ctx->handle); + rows = calloc(total, sizeof(struct tep_record *)); if (!rows) - goto fail; - - n_cpus = tracecmd_cpus(kshark_ctx->handle); + goto fail_free; for (count = 0; count < total; count++) { int next_cpu; @@ -955,6 +949,9 @@ ssize_t kshark_load_data_records(struct kshark_context *kshark_ctx, *data_rows = rows; return total; + fail_free: + free_rec_list(rec_list, n_cpus, type); + fail: fprintf(stderr, "Failed to allocate memory during data loading.\n"); return -ENOMEM;