linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH v4 3/9] kernel-shark-qt: Add API for loading trace.dat files
Date: Mon, 2 Jul 2018 15:03:54 -0400	[thread overview]
Message-ID: <20180702150354.2d643dfd@gandalf.local.home> (raw)
In-Reply-To: <20180702140424.23221-3-y.karadz@gmail.com>

On Mon,  2 Jul 2018 17:04:18 +0300
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:


> +/**
> + * @brief Get an array containing the Process Ids of all tasks presented in
> + *	  the loaded trace data file.
> + * @param kshark_ctx: Input location for context pointer.
> + * @param pids: Output location for the Pids of the tasks. The user is
> + *		responsible for freeing the elements of the outputted array.
> + * @returns The size of the outputted array of Pids in the case of success,
> + *	    or a negative error code on failure.
> + */
> +ssize_t kshark_get_task_pids(struct kshark_context *kshark_ctx, int **pids)
> +{
> +	size_t i, pid_count = 0, pid_size = KS_TASK_HASH_SIZE;
> +	struct kshark_task_list *list;
> +	int *temp_pids;
> +
> +	*pids = calloc(pid_size, sizeof(int));
> +	if(!*pids)
> +		goto fail;
> +
> +	for (i = 0; i < KS_TASK_HASH_SIZE; ++i) {
> +		list = kshark_ctx->tasks[i];
> +		while (list) {
> +			(*pids)[pid_count] = list->pid;
> +			list = list->next;
> +			if (++pid_count >= pid_size) {
> +				pid_size *= 2;
> +				temp_pids = realloc(*pids, pid_size * sizeof(int));
> +				if (!temp_pids) {
> +					goto fail;
> +				}
> +				*pids = temp_pids;
> +			}
> +		}
> +	}
> +
> +	temp_pids = realloc(*pids, pid_count * sizeof(int));
> +	if (!temp_pids)
> +		goto fail;

Almost, but we need:

	*pids = temp_pids;

Otherwise, if the unlikely case of *pids gets reallocated (it shouldn't
because we are shrinking *pids), it gets assigned properly. Yes, I know
I'm being paranoid here, but it's better safe than sorry.

No need to send another patch, I'll add this myself.

Thanks!

-- Steve

> +
> +	return pid_count;
> +
> +fail:
> +	fprintf(stderr, "Failed to allocate memory for Task Pids.\n");
> +	free(*pids);
> +	*pids = NULL;
> +	return -ENOMEM;
> +}
> +

  reply	other threads:[~2018-07-02 19:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-02 14:04 [PATCH v4 1/9] kernel-shark-qt: Add Cmake build system for the Qt based KernelShark Yordan Karadzhov (VMware)
2018-07-02 14:04 ` [PATCH v4 2/9] kernel-shark-qt: Automatic generation of doxygen documentation Yordan Karadzhov (VMware)
2018-07-02 14:04 ` [PATCH v4 3/9] kernel-shark-qt: Add API for loading trace.dat files Yordan Karadzhov (VMware)
2018-07-02 19:03   ` Steven Rostedt [this message]
2018-07-09 15:57   ` Steven Rostedt
2018-07-02 14:04 ` [PATCH v4 4/9] kernel-shark-qt: Add an example showing how to load trace data Yordan Karadzhov (VMware)
2018-07-02 14:04 ` [PATCH v4 5/9] kernel-shark-qt: Add a README file to trace-cmd/kernel-shark-qt Yordan Karadzhov (VMware)
2018-07-02 14:04 ` [PATCH v4 6/9] kernel-shark-qt: Add filtering to the C API of KernelShark Yordan Karadzhov (VMware)
2018-07-02 14:04 ` [PATCH v4 7/9] kernel-shark-qt: Add an example showing how to filter trace data Yordan Karadzhov (VMware)
2018-07-02 14:04 ` [PATCH v4 8/9] kernel-shark-qt: Add Advanced filter to the session context Yordan Karadzhov (VMware)
2018-07-02 14:04 ` [PATCH v4 9/9] kernel-shark-qt: Add example of advanded filtering Yordan Karadzhov (VMware)

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=20180702150354.2d643dfd@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.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).