[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230425130427.39b58745@gandalf.local.home>
Date: Tue, 25 Apr 2023 13:04:27 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: Hao Zeng <zenghao@...inos.cn>
Cc: chenhuacai@...nel.org, zhangqing@...ngson.cn,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] recordmcount: Fix memory leaks in the uwrite
function
On Tue, 25 Apr 2023 10:46:03 +0800
Hao Zeng <zenghao@...inos.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) {
Powered by blists - more mailing lists