Hi,
On Tue, Feb 10, 2026 at 02:48:18PM +0100, Mark Wielaard wrote:
> On Mon, 2026-02-09 at 08:16 -0500, Aaron Merey wrote:
> > If current_path needs to be reallocated, full_path is assigned a newly
> > malloced buffer and then full_path is assigned to current_path. This
> > leaks the previous value of full_path.
> >
> > Free full_path before reassigning it.
> >
> > Signed-off-by: Aaron Merey <[email protected]>
> > ---
> > src/elfclassify.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/src/elfclassify.c b/src/elfclassify.c
> > index 307771b2..80a376a4 100644
> > --- a/src/elfclassify.c
> > +++ b/src/elfclassify.c
> > @@ -866,6 +866,8 @@ check_ar_members (void)
> > bad_ar = true;
> > break;
> > }
> > +
> > + free (full_path);
> > full_path = new_path;
> > }
> >
>
> Oops, my mistake when adding the --any-ar-member option.
> This looks like the right way to fix this.
Can I get back to this one? I think the original mistake was to try to
realloc current_path instead of full_path. What we really want here is
increase the storage of full_path, which then will be assigned to
current_path.
The current[_path] logic is hard to follow right now. And I think the
realloc currently is wrong since current_path might or might not point
to full_path.
The attached simplifies the logic by simply reallocing full_path
directly.
Cheers,
Mark
>From 691aa26781b3b1f6f1bd5b80fd690d61e104793c Mon Sep 17 00:00:00 2001
From: Mark Wielaard <[email protected]>
Date: Tue, 12 May 2026 12:57:11 +0200
Subject: [PATCH] elfclassify: Simplify realloc logic in check_ar_members
The name path logic in check_ar_members is somewhat confusing. At the
start of the while loop going over the member names current_path is
pointing to the archive name (saved in ar_path), then during the loop
it is pointing to the ar member names in full_path, and after
everything is processed current_path is set back to ar_path.
If there isn't enough room in full_path to store the ar member name we
realloc current_path (!) to a bigger size. This might or might not be
full_path. What we should do is realloc full_path itself directly
(which is then assigned to current_path after the ar member name is
setup in full_path).
* src/elfclassify.c (check_ar_members): realloc full_path, not
current_path. Don't free full_path.
Signed-off-by: Mark Wielaard <[email protected]>
---
src/elfclassify.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/elfclassify.c b/src/elfclassify.c
index 80a376a49459..63caebdc7a3b 100644
--- a/src/elfclassify.c
+++ b/src/elfclassify.c
@@ -858,7 +858,7 @@ check_ar_members (void)
if (path_size < strlen (ar_path) + strlen (ar_name) + 3)
{
path_size = strlen (ar_path) + strlen (ar_name) + 24;
- char *new_path = realloc (current_path, path_size);
+ char *new_path = realloc (full_path, path_size);
if (new_path == NULL)
{
issue (ENOMEM, N_("allocating a member string name storage"));
@@ -867,7 +867,6 @@ check_ar_members (void)
break;
}
- free (full_path);
full_path = new_path;
}
--
2.53.0