In the struct smb_Dir destructor, use the fsp back pointer to release resources.
authorJeremy Allison <jra@samba.org>
Wed, 10 Apr 2013 23:24:15 +0000 (16:24 -0700)
committerKarolin Seeger <kseeger@samba.org>
Wed, 5 Jun 2013 10:02:42 +0000 (12:02 +0200)
Removes one use of dirfd().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
(cherry picked from commit ea14c9443178da9ae6ccbe71e573156396f6f699)

source3/smbd/dir.c

index 7cb5ffde02b6b71176a36c6d4e70de30d352b40b..19f07f340034fa6502ec0674606ffde459faeb63 100644 (file)
@@ -1347,18 +1347,21 @@ bool is_visible_file(connection_struct *conn, const char *dir_path,
 
 static int smb_Dir_destructor(struct smb_Dir *dirp)
 {
-       if (dirp->dir) {
-#ifdef HAVE_DIRFD
-               if (dirp->conn->sconn) {
-                       files_struct *fsp = file_find_fd(dirp->conn->sconn,
-                                               dirfd(dirp->dir));
-                       if (fsp) {
-                               /* The call below closes the underlying fd. */
-                               fsp->fh->fd = -1;
+       if (dirp->dir != NULL) {
+               SMB_VFS_CLOSEDIR(dirp->conn,dirp->dir);
+               if (dirp->fsp != NULL) {
+                       /*
+                        * The SMB_VFS_CLOSEDIR above
+                        * closes the underlying fd inside
+                        * dirp->fsp.
+                        */
+                       dirp->fsp->fh->fd = -1;
+                       if (dirp->fsp->dptr != NULL) {
+                               SMB_ASSERT(dirp->fsp->dptr->dir_hnd == dirp);
+                               dirp->fsp->dptr->dir_hnd = NULL;
                        }
+                       dirp->fsp = NULL;
                }
-#endif
-               SMB_VFS_CLOSEDIR(dirp->conn,dirp->dir);
        }
        if (dirp->conn->sconn && !dirp->conn->sconn->using_smb2) {
                dirp->conn->sconn->searches.dirhandles_open--;