diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2006-03-03 20:19:26 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2006-03-03 20:19:26 +0000 |
commit | ecdee6e98ab783d321b1ffe9a10d09e19e19eb6d (patch) | |
tree | 6ca1b117ac97ea951c04c3342cd314b61f6f0b6c /winsup/cygwin/fhandler_disk_file.cc | |
parent | 961fe49069358eb66381c5e1ac56681e5cf4e5b2 (diff) | |
download | cygnal-ecdee6e98ab783d321b1ffe9a10d09e19e19eb6d.tar.gz cygnal-ecdee6e98ab783d321b1ffe9a10d09e19e19eb6d.tar.bz2 cygnal-ecdee6e98ab783d321b1ffe9a10d09e19e19eb6d.zip |
* dir.cc (opendir): Fix indentation.
* fhandler_disk_file.cc (fhandler_disk_file::opendir): Move storing
fhandler in file descriptor table to some point very late in function
to avoid double free'ing. Add comment to explain what happens.
Add label free_mounts and don't forget to delete __DIR_mounts structure
if NtOpenFile fails.
Diffstat (limited to 'winsup/cygwin/fhandler_disk_file.cc')
-rw-r--r-- | winsup/cygwin/fhandler_disk_file.cc | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index dc46cbcef..0c1ed37ab 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -1542,10 +1542,6 @@ fhandler_disk_file::opendir () if (fd < 0) goto free_dirent; - fd = this; - fd->nohandle (true); - dir->__d_fd = fd; - dir->__fh = this; /* FindFirstFile doesn't seem to like duplicate /'s. The dirname is generated with trailing backslash here which simplifies later usage of dirname for checking symlinks. @@ -1583,7 +1579,7 @@ fhandler_disk_file::opendir () if (!NT_SUCCESS (status)) { __seterrno_from_nt_status (status); - goto free_dirent; + goto free_mounts; } /* FileIdBothDirectoryInformation is apparently unsupported on XP @@ -1602,12 +1598,22 @@ fhandler_disk_file::opendir () } } } + /* Filling fd with `this' (aka storing this in the file descriptor table + should only happen after it's clear that opendir doesn't fail, + otherwise we end up cfree'ing the fhandler twice, once in opendir() + in dir.cc, the second time on exit. Nasty, nasty... */ + fd = this; + fd->nohandle (true); + dir->__d_fd = fd; + dir->__fh = this; res = dir; } syscall_printf ("%p = opendir (%s)", res, get_name ()); return res; +free_mounts: + delete d_mounts (dir); free_dirent: free (dir->__d_dirent); free_dirname: |