1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2025-02-17 02:31:41 +01:00

(maps_init): Correct initialization of mi->buf.

(maps_close): Don't forget to unmap mi->buf if it's non-NULL.

(Logical change 1.209)
This commit is contained in:
mostang.com!davidm 2004-04-21 07:24:35 +00:00
parent 72e5a3bc17
commit 2f210753bd

View file

@ -72,13 +72,19 @@ maps_init (struct map_iterator *mi, pid_t pid)
mi->fd = open (path, O_RDONLY);
mi->offset = 0;
/* Try to allocate a page-sized buffer. If that fails, we'll fall
back on reading one line at a time. */
mi->buf_size = getpagesize ();
cp = mmap (0, mi->buf_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (cp == MAP_FAILED)
cp = NULL;
cp = NULL;
if (mi->fd >= 0)
{
/* Try to allocate a page-sized buffer. If that fails, we'll
fall back on reading one line at a time. */
mi->buf_size = getpagesize ();
cp = mmap (0, mi->buf_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (cp == MAP_FAILED)
cp = NULL;
else
cp += mi->buf_size;
}
mi->buf = mi->buf_end = cp;
}
@ -285,6 +291,11 @@ maps_close (struct map_iterator *mi)
return;
close (mi->fd);
mi->fd = -1;
if (mi->buf)
{
munmap (mi->buf_end - mi->buf_size, mi->buf_size);
mi->buf = mi->buf_end = 0;
}
}
#endif /* os_linux_h */