public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] On elf_update, remember when we mmap()
@ 2017-04-20 14:57 Ulf Hermann
  2017-04-28  8:48 ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Ulf Hermann @ 2017-04-20 14:57 UTC (permalink / raw)
  To: elfutils-devel

Otherwise we skip the munmap() later. This leaks resources.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
---
 libelf/ChangeLog    | 4 ++++
 libelf/elf_update.c | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index fa768f8..225c7c8 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,5 +1,9 @@
 2017-04-20  Ulf Hermann  <ulf.hermann@qt.io>
 
+	* elf_update.c: Set ELF_F_MMAPPED flag if we mmap from elf_update.
+
+2017-04-20  Ulf Hermann  <ulf.hermann@qt.io>
+
 	* libelfP.h: Don't include config.h.
 
 2017-04-20  Ulf Hermann  <ulf.hermann@qt.io>
diff --git a/libelf/elf_update.c b/libelf/elf_update.c
index c635eb3..8ce0782 100644
--- a/libelf/elf_update.c
+++ b/libelf/elf_update.c
@@ -74,6 +74,8 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum)
 			       MAP_SHARED, elf->fildes, 0);
       if (unlikely (elf->map_address == MAP_FAILED))
 	elf->map_address = NULL;
+      else
+	elf->flags |= ELF_F_MMAPPED;
     }
 
   if (elf->map_address != NULL)
-- 
2.1.4

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

* Re: [PATCH] On elf_update, remember when we mmap()
  2017-04-20 14:57 [PATCH] On elf_update, remember when we mmap() Ulf Hermann
@ 2017-04-28  8:48 ` Mark Wielaard
  2017-04-28 11:15   ` Ulf Hermann
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2017-04-28  8:48 UTC (permalink / raw)
  To: Ulf Hermann; +Cc: elfutils-devel

On Thu, Apr 20, 2017 at 04:57:41PM +0200, Ulf Hermann wrote:
> Otherwise we skip the munmap() later. This leaks resources.

Oops. Good find. Applied to master.

When configured --with-valgrind the tests are run under valgrind
and memory leaks will fail the tests. But since this is mmap
valgrind won't report it. How did you find it?

Thanks,

Mark

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

* Re: [PATCH] On elf_update, remember when we mmap()
  2017-04-28  8:48 ` Mark Wielaard
@ 2017-04-28 11:15   ` Ulf Hermann
  0 siblings, 0 replies; 3+ messages in thread
From: Ulf Hermann @ 2017-04-28 11:15 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

On 04/28/2017 12:23 AM, Mark Wielaard wrote:
> On Thu, Apr 20, 2017 at 04:57:41PM +0200, Ulf Hermann wrote:
>> Otherwise we skip the munmap() later. This leaks resources.
> 
> Oops. Good find. Applied to master.
> 
> When configured --with-valgrind the tests are run under valgrind
> and memory leaks will fail the tests. But since this is mmap
> valgrind won't report it. How did you find it?

On windows you cannot rename or unlink files if there are still open views on it (and the win32 view mechanism is how I implement mmap on windows). So, the test cases fail then because the directories are not empty.

Ulf

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

end of thread, other threads:[~2017-04-28  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-20 14:57 [PATCH] On elf_update, remember when we mmap() Ulf Hermann
2017-04-28  8:48 ` Mark Wielaard
2017-04-28 11:15   ` Ulf Hermann

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