From: Yordan Karadzhov <ykaradzhov@vmware.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org, y.karadz@gmail.com,
Yordan Karadzhov <ykaradzhov@vmware.com>
Subject: [PATCH 3/3] kernel-shark: Correct memory management when data loading fails
Date: Thu, 23 May 2019 18:09:46 +0300 [thread overview]
Message-ID: <20190523150946.30769-4-ykaradzhov@vmware.com> (raw)
In-Reply-To: <20190523150946.30769-1-ykaradzhov@vmware.com>
The erroneous case, when the memory allocation failed during data loading,
hasn't been properly handled.
Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
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;
--
2.20.1
prev parent reply other threads:[~2019-05-23 15:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-23 15:09 [PATCH 0/3] Fixes toward KS 1.0 Yordan Karadzhov
2019-05-23 15:09 ` [PATCH 1/3] kernel-shark: Add Doxygen documentation for KsGLWidget::update() Yordan Karadzhov
2019-05-23 15:09 ` [PATCH 2/3] kernel-shark: Handle properly the negative error codes when loading data Yordan Karadzhov
2019-05-23 15:09 ` Yordan Karadzhov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190523150946.30769-4-ykaradzhov@vmware.com \
--to=ykaradzhov@vmware.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=y.karadz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).