Skip to content

Commit fa359d0

Browse files
Hao Zengrostedt
authored andcommitted
recordmcount: Fix memory leaks in the uwrite function
Common realloc mistake: 'file_append' nulled but not freed upon failure Link: https://lkml.kernel.org/r/20230426010527.703093-1-zenghao@kylinos.cn Signed-off-by: Hao Zeng <zenghao@kylinos.cn> Suggested-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 41d8fba commit fa359d0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

scripts/recordmcount.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,18 @@ static ssize_t uwrite(void const *const buf, size_t const count)
110110
{
111111
size_t cnt = count;
112112
off_t idx = 0;
113+
void *p = NULL;
113114

114115
file_updated = 1;
115116

116117
if (file_ptr + count >= file_end) {
117118
off_t aoffset = (file_ptr + count) - file_end;
118119

119120
if (aoffset > file_append_size) {
120-
file_append = realloc(file_append, aoffset);
121+
p = realloc(file_append, aoffset);
122+
if (!p)
123+
free(file_append);
124+
file_append = p;
121125
file_append_size = aoffset;
122126
}
123127
if (!file_append) {

0 commit comments

Comments
 (0)