1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-09 21:40:33 +02:00

don't leak file descriptors when mmaping objcode

* libguile/objcodes.c (make_objcode_from_file): Close the mmap'd file,
  so that we don't leak the descriptor.  I was previously under the
  mistaken impression that closing the fd unmapped the memory, which is
  not the case.  Thanks to Cedric Cellier for the tip!
This commit is contained in:
Andy Wingo 2012-01-07 02:07:09 +01:00
parent ab66fb3cd1
commit 213544e0dc

View file

@ -145,7 +145,7 @@ verify_cookie (char *cookie, struct stat *st, int map_fd, void *map_addr)
- scm_tc7_objcode | type | flags - scm_tc7_objcode | type | flags
- the struct scm_objcode C object - the struct scm_objcode C object
- the parent of this objcode: either another objcode, a bytevector, - the parent of this objcode: either another objcode, a bytevector,
or, in the case of mmap types, file descriptors (as an inum) or, in the case of mmap types, #f
- "native code" -- not currently used. - "native code" -- not currently used.
*/ */
@ -203,12 +203,11 @@ make_objcode_from_file (int fd)
scm_from_size_t (total_len))); scm_from_size_t (total_len)));
} }
/* FIXME: we leak ourselves and the file descriptor. but then again so does (void) close (fd);
dlopen(). */
return scm_permanent_object return scm_permanent_object
(scm_double_cell (SCM_MAKE_OBJCODE_TAG (SCM_OBJCODE_TYPE_MMAP, 0), (scm_double_cell (SCM_MAKE_OBJCODE_TAG (SCM_OBJCODE_TYPE_MMAP, 0),
(scm_t_bits)(addr + strlen (SCM_OBJCODE_COOKIE)), (scm_t_bits)(addr + strlen (SCM_OBJCODE_COOKIE)),
SCM_UNPACK (scm_from_int (fd)), 0)); SCM_BOOL_F_BITS, 0));
} }
#else #else
{ {