diff options
author | mostang.com!davidm <mostang.com!davidm> | 2004-04-21 07:24:35 +0000 |
---|---|---|
committer | mostang.com!davidm <mostang.com!davidm> | 2004-04-21 07:24:35 +0000 |
commit | 2f210753bd631692bd93f4d0a90e9195424075b9 (patch) | |
tree | e44923abcb60ac1f0843ebdb460fd71719f9852c /src/os-linux.h | |
parent | 72e5a3bc176fce0eb09e70ab6ffe1be7ba55a2de (diff) | |
download | libunwind-2f210753bd631692bd93f4d0a90e9195424075b9.tar.gz |
(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)
Diffstat (limited to 'src/os-linux.h')
-rw-r--r-- | src/os-linux.h | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/os-linux.h b/src/os-linux.h index f01f7a50..7e11dae5 100644 --- a/src/os-linux.h +++ b/src/os-linux.h @@ -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 */ |