The erroneous case, when the memory allocation failed during data loading, hasn't been properly handled. Signed-off-by: Yordan Karadzhov <ykaradzhov@xxxxxxxxxx> --- 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
![]() |