public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] segment: Fix memory leak in insert()
@ 2024-04-02 20:32 Maks Mishin
  2024-04-03 20:34 ` Mark Wielaard
  0 siblings, 1 reply; 4+ messages in thread
From: Maks Mishin @ 2024-04-02 20:32 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Maks Mishin, Marek Polacek

Dynamic memory, referenced by 'naddr', is allocated at segment.c:66
by calling function 'realloc' and lost at segment.c:92.

Found by RASU JSC.

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

diff --git a/libdwfl/segment.c b/libdwfl/segment.c
index f6a3e84e..618c14e6 100644
--- a/libdwfl/segment.c
+++ b/libdwfl/segment.c
@@ -89,6 +89,7 @@ insert (Dwfl *dwfl, size_t i, GElf_Addr start, GElf_Addr end, int segndx)
 	      return true;
 	    }
 	}
+	    free (naddr);
     }
 
   if (unlikely (i < dwfl->lookup_elts))
-- 
2.30.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] segment: Fix memory leak in insert()
  2024-04-02 20:32 [PATCH] segment: Fix memory leak in insert() Maks Mishin
@ 2024-04-03 20:34 ` Mark Wielaard
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Wielaard @ 2024-04-03 20:34 UTC (permalink / raw)
  To: Maks Mishin; +Cc: elfutils-devel, Marek Polacek

On Tue, Apr 02, 2024 at 11:32:50PM +0300, Maks Mishin wrote:
> Dynamic memory, referenced by 'naddr', is allocated at segment.c:66
> by calling function 'realloc' and lost at segment.c:92.

It isn't lost, it is assigned to dwfl->lookup_addr at segment.c:77

> 
> Found by RASU JSC.
> 
> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> ---
>  libdwfl/segment.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/libdwfl/segment.c b/libdwfl/segment.c
> index f6a3e84e..618c14e6 100644
> --- a/libdwfl/segment.c
> +++ b/libdwfl/segment.c
> @@ -89,6 +89,7 @@ insert (Dwfl *dwfl, size_t i, GElf_Addr start, GElf_Addr end, int segndx)
>  	      return true;
>  	    }
>  	}
> +	    free (naddr);
>      }
>  
>    if (unlikely (i < dwfl->lookup_elts))
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] segment: Fix memory leak in insert()
  2024-04-01 17:25 Maks Mishin
@ 2024-04-01 19:10 ` Marek Polacek
  0 siblings, 0 replies; 4+ messages in thread
From: Marek Polacek @ 2024-04-01 19:10 UTC (permalink / raw)
  To: Maks Mishin; +Cc: elfutils-devel

On Mon, Apr 01, 2024 at 08:25:13PM +0300, Maks Mishin wrote:
> Dynamic memory, referenced by 'naddr', is allocated at segment.c:66
> by calling function 'realloc' and lost at segment.c:92.
> 
> Found by RASU JSC.
> 
> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> ---
>  libdwfl/segment.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libdwfl/segment.c b/libdwfl/segment.c
> index f6a3e84e..5d6053e4 100644
> --- a/libdwfl/segment.c
> +++ b/libdwfl/segment.c
> @@ -89,6 +89,8 @@ insert (Dwfl *dwfl, size_t i, GElf_Addr start, GElf_Addr end, int segndx)
>  	      return true;
>  	    }
>  	}
> +	  if (naddr != NULL)

You don't need this check.

> +	    free(naddr);

Nit: there should be a space before '('.

Thanks for the patch,
Marek


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] segment: Fix memory leak in insert()
@ 2024-04-01 17:25 Maks Mishin
  2024-04-01 19:10 ` Marek Polacek
  0 siblings, 1 reply; 4+ messages in thread
From: Maks Mishin @ 2024-04-01 17:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Maks Mishin

Dynamic memory, referenced by 'naddr', is allocated at segment.c:66
by calling function 'realloc' and lost at segment.c:92.

Found by RASU JSC.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
---
 libdwfl/segment.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libdwfl/segment.c b/libdwfl/segment.c
index f6a3e84e..5d6053e4 100644
--- a/libdwfl/segment.c
+++ b/libdwfl/segment.c
@@ -89,6 +89,8 @@ insert (Dwfl *dwfl, size_t i, GElf_Addr start, GElf_Addr end, int segndx)
 	      return true;
 	    }
 	}
+	  if (naddr != NULL)
+	    free(naddr);
     }
 
   if (unlikely (i < dwfl->lookup_elts))
-- 
2.30.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-03 20:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-02 20:32 [PATCH] segment: Fix memory leak in insert() Maks Mishin
2024-04-03 20:34 ` Mark Wielaard
  -- strict thread matches above, loose matches on Subject: below --
2024-04-01 17:25 Maks Mishin
2024-04-01 19:10 ` Marek Polacek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).