From: Steven Rostedt <rostedt@goodmis.org>
To: Hao Zeng <zenghao@kylinos.cn>
Cc: chenhuacai@kernel.org, zhangqing@loongson.cn,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] recordmcount: Fix memory leaks in the uwrite function
Date: Tue, 25 Apr 2023 13:04:27 -0400 [thread overview]
Message-ID: <20230425130427.39b58745@gandalf.local.home> (raw)
In-Reply-To: <20230425024603.4005251-1-zenghao@kylinos.cn>
On Tue, 25 Apr 2023 10:46:03 +0800
Hao Zeng <zenghao@kylinos.cn> wrote:
> @@ -117,7 +118,13 @@ static ssize_t uwrite(void const *const buf, size_t const count)
> off_t aoffset = (file_ptr + count) - file_end;
>
> if (aoffset > file_append_size) {
> - file_append = realloc(file_append, aoffset);
> + p = realloc(file_append, aoffset);
> + if (!p) {
> + free(file_append);
> + file_append = NULL;
> + } else {
> + file_append = p;
> + }
You can simplify the above with:
if (!p)
free(file_append);
file_append = p;
-- Steve
> file_append_size = aoffset;
> }
> if (!file_append) {
prev parent reply other threads:[~2023-04-25 17:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-25 2:46 Hao Zeng
2023-04-25 17:04 ` Steven Rostedt [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=20230425130427.39b58745@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=chenhuacai@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=zenghao@kylinos.cn \
--cc=zhangqing@loongson.cn \
/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
all inboxes | Powered by JetHome®