X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ffchdir.c;fp=lib%2Ffchdir.c;h=545b207ff4b6fb21175e3da817cbf9a28fb1c13a;hb=aeb9a8a8a97f8b876a378ae4fe330f131437b348;hp=4cc0f33ce49ab1794898ab213d2a50b40e933afb;hpb=5aad650f4e093269e4184cb150f735f6999784d6;p=gnulib.git diff --git a/lib/fchdir.c b/lib/fchdir.c index 4cc0f33ce..545b207ff 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;