Linux btrace development
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: 303146950@qq.com, linux-btrace@vger.kernel.org
Cc: Kou Wenqi <kouwenqi@kylinos.cn>
Subject: Re: [PATCH v3] blkparse: Fix a potential coredump issue
Date: Wed, 19 Mar 2025 07:10:58 -0600	[thread overview]
Message-ID: <1962cea3-e413-441c-b98a-ded4a6a4fe68@kernel.dk> (raw)
In-Reply-To: <tencent_DE806EEE1852F9E79115172254B8A2789207@qq.com>

On 3/19/25 7:02 AM, 303146950@qq.com wrote:
> diff --git a/blkparse.c b/blkparse.c
> index 9d2029a..d6aaa8b 100644
> --- a/blkparse.c
> +++ b/blkparse.c
> @@ -1022,7 +1022,7 @@ static struct io_track *find_track(struct per_dev_info *pdi, pid_t pid,
>  	if (!iot) {
>  		struct io_track_req *req;
>  
> -		req = malloc(sizeof(*req) + sizeof(*iot));
> +		req = calloc(1, sizeof(*req) + sizeof(*iot));
>  		req->ppm = find_ppm(pid);
>  		if (!req->ppm)
>  			req->ppm = add_ppm_hash(pid, "unknown");
> @@ -1106,7 +1106,7 @@ static void log_track_split(struct per_dev_info *pdi, struct blk_io_trace *t)
>  	 * parts.
>  	 */
>  	iot = find_track(pdi, t->pid, t->sector);
> -	split = malloc(sizeof(*iot));
> +	split = calloc(1, sizeof(*iot));
>  	split->req = iot->req;
>  	split->next = iot->next;
>  	iot->next = split;

Nit picking, but the idiomatic way would be to make it calloc(size, 1)
not the other way around. The first one is the size, the 2nd one is the
number of them.

-- 
Jens Axboe

  reply	other threads:[~2025-03-19 13:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-19 13:02 [PATCH v3] blkparse: Fix a potential coredump issue 303146950
2025-03-19 13:10 ` Jens Axboe [this message]
2025-03-20  1:49   ` 303146950
2025-03-20 11:07     ` Jens Axboe
2025-03-20 11:07 ` Jens Axboe

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=1962cea3-e413-441c-b98a-ded4a6a4fe68@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=303146950@qq.com \
    --cc=kouwenqi@kylinos.cn \
    --cc=linux-btrace@vger.kernel.org \
    /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