public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA] fix leak in gdb_environ
@ 2022-11-27 18:25 Philippe Waroquiers
  2022-11-27 18:41 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Waroquiers @ 2022-11-27 18:25 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

valgrind reports a leak when assigning a gdb_environ to another gdb_environ.
The memory allocated for the target gdb_environ env variables is not released.
The gdb_environ selftest reproduces the leak (see below).
Fix the leak by clearing the target gbd_environ before std::move-ing the
members.

Tested natively and re-running all tests under valgrind.

==3261873== 4,842 bytes in 69 blocks are definitely lost in loss record 6,772 of 6,839
==3261873==    at 0x483979B: malloc (vg_replace_malloc.c:393)
==3261873==    by 0x25A454: xmalloc (alloc.c:57)
==3261873==    by 0x7D1E4E: xstrdup (xstrdup.c:34)
==3261873==    by 0x7E2A51: gdb_environ::from_host_environ() (environ.cc:56)
==3261873==    by 0x66F1C8: test_reinit_from_host_environ (environ-selftests.c:78)
==3261873==    by 0x66F1C8: selftests::gdb_environ_tests::run_tests() (environ-selftests.c:285)
==3261873==    by 0x7EFC43: operator() (std_function.h:622)
=
---
 gdbsupport/environ.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gdbsupport/environ.cc b/gdbsupport/environ.cc
index f5f6b38e19c..2d8e3ea6e92 100644
--- a/gdbsupport/environ.cc
+++ b/gdbsupport/environ.cc
@@ -29,6 +29,8 @@ gdb_environ::operator= (gdb_environ &&e)
   if (&e == this)
     return *this;
 
+  this->clear ();
+
   m_environ_vector = std::move (e.m_environ_vector);
   m_user_set_env = std::move (e.m_user_set_env);
   m_user_unset_env = std::move (e.m_user_unset_env);
-- 
2.30.2


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

* Re: [RFA] fix leak in gdb_environ
  2022-11-27 18:25 [RFA] fix leak in gdb_environ Philippe Waroquiers
@ 2022-11-27 18:41 ` Simon Marchi
  2022-11-27 20:16   ` Philippe Waroquiers
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2022-11-27 18:41 UTC (permalink / raw)
  To: Philippe Waroquiers, gdb-patches



On 11/27/22 13:25, Philippe Waroquiers via Gdb-patches wrote:
> valgrind reports a leak when assigning a gdb_environ to another gdb_environ.
> The memory allocated for the target gdb_environ env variables is not released.
> The gdb_environ selftest reproduces the leak (see below).
> Fix the leak by clearing the target gbd_environ before std::move-ing the

gbd_environ -> gdb_environ

Otherwise:

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

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

* Re: [RFA] fix leak in gdb_environ
  2022-11-27 18:41 ` Simon Marchi
@ 2022-11-27 20:16   ` Philippe Waroquiers
  0 siblings, 0 replies; 3+ messages in thread
From: Philippe Waroquiers @ 2022-11-27 20:16 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On Sun, 2022-11-27 at 13:41 -0500, Simon Marchi wrote:
> 
> On 11/27/22 13:25, Philippe Waroquiers via Gdb-patches wrote:
> > valgrind reports a leak when assigning a gdb_environ to another gdb_environ.
> > The memory allocated for the target gdb_environ env variables is not released.
> > The gdb_environ selftest reproduces the leak (see below).
> > Fix the leak by clearing the target gbd_environ before std::move-ing the
> 
> gbd_environ -> gdb_environ
> 
> Otherwise:
> 
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
Thanks for the review, pushed with the tag added.



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

end of thread, other threads:[~2022-11-27 20:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-27 18:25 [RFA] fix leak in gdb_environ Philippe Waroquiers
2022-11-27 18:41 ` Simon Marchi
2022-11-27 20:16   ` Philippe Waroquiers

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).