tools/testing/selftests/mm/mremap_test.c | 1 + 1 file changed, 1 insertion(+)
is_range_mapped() uses getline() to read /proc/self/maps line by
line, but never frees the buffer it allocates. Every exit path
(parse failure, match found, or reaching EOF) returns without
calling free(line), leaking the buffer on each call. The function
is called multiple times in this test, so the leak accumulates
across calls.
Free line before returning.
Signed-off-by: Anshuman <anshumantewari123@gmail.com>
---
tools/testing/selftests/mm/mremap_test.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c
index 131d9d6db..779ef2d5f 100644
--- a/tools/testing/selftests/mm/mremap_test.c
+++ b/tools/testing/selftests/mm/mremap_test.c
@@ -156,6 +156,7 @@ static bool is_range_mapped(FILE *maps_fp, unsigned long start,
}
}
+ free(line);
return success;
}
--
2.55.0
On Wed, 26 Aug 2026 11:43:00 +0530 Anshuman <anshumantewari123@gmail.com> wrote: > is_range_mapped() uses getline() to read /proc/self/maps line by > line, but never frees the buffer it allocates. Every exit path > (parse failure, match found, or reaching EOF) returns without > calling free(line), leaking the buffer on each call. The function > is called multiple times in this test, so the leak accumulates > across calls. > > Free line before returning. Makes sense to me. > > Signed-off-by: Anshuman <anshumantewari123@gmail.com> Reviewed-by: SJ Park <sj@kernel.org> Thanks, SJ [...]
On 8/26/26 08:13, Anshuman wrote: > is_range_mapped() uses getline() to read /proc/self/maps line by > line, but never frees the buffer it allocates. Every exit path > (parse failure, match found, or reaching EOF) returns without > calling free(line), leaking the buffer on each call. The function > is called multiple times in this test, so the leak accumulates > across calls. > > Free line before returning. > > Signed-off-by: Anshuman <anshumantewari123@gmail.com> > --- Looks good, I don't think Fixes is needed (even though called multiple times, the effective waste should not be relevant on any realistic system). Thanks! Acked-by: David Hildenbrand (Arm) <david@kernel.org> -- Cheers, David
Thanks, David — appreciate the ack. Anshuman On Wed, 26 Aug 2026 at 13:08, David Hildenbrand (Arm) <david@kernel.org> wrote: > > On 8/26/26 08:13, Anshuman wrote: > > is_range_mapped() uses getline() to read /proc/self/maps line by > > line, but never frees the buffer it allocates. Every exit path > > (parse failure, match found, or reaching EOF) returns without > > calling free(line), leaking the buffer on each call. The function > > is called multiple times in this test, so the leak accumulates > > across calls. > > > > Free line before returning. > > > > Signed-off-by: Anshuman <anshumantewari123@gmail.com> > > --- > > Looks good, I don't think Fixes is needed (even though called multiple times, > the effective waste should not be relevant on any realistic system). > > Thanks! > > Acked-by: David Hildenbrand (Arm) <david@kernel.org> > > -- > Cheers, > > David
© 2016 - 2026 Red Hat, Inc.