-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Jim Meyering on 12/8/2009 7:51 AM: > Eric Blake wrote: >> fchdir is working on mingw, which is about the only modern portability >> target that lacks fchdir, but it is sure easier to test on other platforms >> than mingw. >> Subject: [PATCH 2/2] fchdir: fix logic bugs > ... > Good catch. > The rest looks fine, too.
Another one. There is a memory leak if you call _gl_register_dup() to the same target without closing the fd in between. This is possible at least in some code paths (such as dup3) when I forced the fchdir replacement even though the native one works; I did not audit whether mingw was subject to the leak even though mingw is the only platform likely to be hit in practice (since most other platforms have fchdir). - -- Don't work too hard, make some time for fun as well! Eric Blake [email protected] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAksfJVcACgkQ84KuGfSFAYCmLgCeNVfLKH2Dv2fO45SVve1cKFcv coIAoLrcqAvtiuBhrE023W8L4MeAtN3W =fGuB -----END PGP SIGNATURE-----
>From aeb9a8a8a97f8b876a378ae4fe330f131437b348 Mon Sep 17 00:00:00 2001 From: Eric Blake <[email protected]> Date: Tue, 8 Dec 2009 10:23:27 -0700 Subject: [PATCH] fchdir: avoid memory leak on re-registration. Some code paths (such as dup3) could overwrite one registered directory fd with another, and must not leak the old name. * lib/fchdir.c (ensure_dirs_slot): Avoid memory leak. Signed-off-by: Eric Blake <[email protected]> --- ChangeLog | 5 +++++ lib/fchdir.c | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0afec2e..8597a13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-12-08 Eric Blake <[email protected]> + + fchdir: avoid memory leak on re-registration. + * lib/fchdir.c (ensure_dirs_slot): Avoid memory leak. + 2009-12-08 Jim Meyering <[email protected]> init.sh: avoid Solaris 10 /bin/sh portability problem diff --git a/lib/fchdir.c b/lib/fchdir.c index 4cc0f33..545b207 100644 --- a/lib/fchdir.c +++ b/lib/fchdir.c @@ -60,12 +60,15 @@ typedef struct static dir_info_t *dirs; static size_t dirs_allocated; -/* Try to ensure dirs has enough room for a slot at index fd. Return - false and set errno to ENOMEM on allocation failure. */ +/* Try to ensure dirs has enough room for a slot at index fd; free any + contents already in that slot. Return false and set errno to + ENOMEM on allocation failure. */ static bool ensure_dirs_slot (size_t fd) { - if (fd >= dirs_allocated) + if (fd < dirs_allocated) + free (dirs[fd].name); + else { size_t new_allocated; dir_info_t *new_dirs; -- 1.6.5.rc1
