elflint: Fix memory leak in check_gnu_hash function

Message ID 20240918085807.79806-1-maks.mishinFZ@gmail.com
State Committed
Headers
Series elflint: Fix memory leak in check_gnu_hash function |

Commit Message

Maks Mishin Sept. 18, 2024, 8:58 a.m. UTC
  Dynamic memory, referenced by 'collected', is allocated at elflint.c:2235
and lost at elflint.c:2296.

Found by RASU JSC with SVACE.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
---
 src/elflint.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Aaron Merey Sept. 20, 2024, 4:07 p.m. UTC | #1
Hi Maks,

On Wed, Sep 18, 2024 at 4:58 AM Maks Mishin <maks.mishinfz@gmail.com> wrote:
>
> Dynamic memory, referenced by 'collected', is allocated at elflint.c:2235
> and lost at elflint.c:2296.
>
> Found by RASU JSC with SVACE.
>
> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> ---
>  src/elflint.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/src/elflint.c b/src/elflint.c
> index e56e1465..cdc6108d 100644
> --- a/src/elflint.c
> +++ b/src/elflint.c
> @@ -2293,6 +2293,7 @@ section [%2d] '%s': hash value for symbol %u in chain for bucket %zu wrong\n"),
>  section [%2d] '%s': mask index for symbol %u in chain for bucket %zu wrong\n"),
>                              idx, section_name (ebl, idx), symidx,
>                              cnt - (4 + bitmask_words));
> +                     free (collected.p32);
>                       return;
>                     }
>                   if (classbits == 32)
> --
> 2.34.1
>

Thanks, merged as commit b47bdee08a1607

Aaron
  
Maks Mishin Sept. 20, 2024, 6:45 p.m. UTC | #2
Thanks for the feedback!

пт, 20 сент. 2024 г. в 19:07, Aaron Merey <amerey@redhat.com>:

> Hi Maks,
>
> On Wed, Sep 18, 2024 at 4:58 AM Maks Mishin <maks.mishinfz@gmail.com>
> wrote:
> >
> > Dynamic memory, referenced by 'collected', is allocated at elflint.c:2235
> > and lost at elflint.c:2296.
> >
> > Found by RASU JSC with SVACE.
> >
> > Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> > ---
> >  src/elflint.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/src/elflint.c b/src/elflint.c
> > index e56e1465..cdc6108d 100644
> > --- a/src/elflint.c
> > +++ b/src/elflint.c
> > @@ -2293,6 +2293,7 @@ section [%2d] '%s': hash value for symbol %u in
> chain for bucket %zu wrong\n"),
> >  section [%2d] '%s': mask index for symbol %u in chain for bucket %zu
> wrong\n"),
> >                              idx, section_name (ebl, idx), symidx,
> >                              cnt - (4 + bitmask_words));
> > +                     free (collected.p32);
> >                       return;
> >                     }
> >                   if (classbits == 32)
> > --
> > 2.34.1
> >
>
> Thanks, merged as commit b47bdee08a1607
>
> Aaron
>
> --
С уважением,
Мишин Максим Александрович
+7 (915) 958-41-07
maks.mishinFZ@gmail.com
  

Patch

diff --git a/src/elflint.c b/src/elflint.c
index e56e1465..cdc6108d 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -2293,6 +2293,7 @@  section [%2d] '%s': hash value for symbol %u in chain for bucket %zu wrong\n"),
 section [%2d] '%s': mask index for symbol %u in chain for bucket %zu wrong\n"),
 			     idx, section_name (ebl, idx), symidx,
 			     cnt - (4 + bitmask_words));
+		      free (collected.p32);
 		      return;
 		    }
 		  if (classbits == 32)