diff options
author | Jeremy Allison <jra@samba.org> | 2013-04-09 10:29:47 -0700 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2013-08-12 09:09:43 +0200 |
commit | 94f7d0cdbb859842613f3c0acfeb36965f54635a (patch) | |
tree | 69bade06bf0a9a60f16eb542e4d674cc8247d75f /source3 | |
parent | d302cb6faee3282379d87e2c65dde392ab6a1750 (diff) | |
download | samba-94f7d0cdbb859842613f3c0acfeb36965f54635a.tar.gz |
Clean error paths in opendir and fd_opendir by only setting handle data on success.
Pass extra struct dirsort_privates * to open_and_sort_dir() function
to avoid it having to re-read the handle data.
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
(cherry picked from commit a2da5a78c48e9be6ec2ecad99ddd23d4773b2267)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/modules/vfs_dirsort.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/source3/modules/vfs_dirsort.c b/source3/modules/vfs_dirsort.c index 3b7f57a78c0..82b96eb3eca 100644 --- a/source3/modules/vfs_dirsort.c +++ b/source3/modules/vfs_dirsort.c @@ -40,7 +40,8 @@ static void free_dirsort_privates(void **datap) { TALLOC_FREE(*datap); } -static bool open_and_sort_dir (vfs_handle_struct *handle) +static bool open_and_sort_dir(vfs_handle_struct *handle, + struct dirsort_privates *data) { struct stat dir_stat; unsigned int i; @@ -115,14 +116,15 @@ static SMB_STRUCT_DIR *dirsort_opendir(vfs_handle_struct *handle, data->fd = dirfd(data->source_directory); - SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates, - struct dirsort_privates, return NULL); - - if (!open_and_sort_dir(handle)) { + if (!open_and_sort_dir(handle, data)) { SMB_VFS_NEXT_CLOSEDIR(handle,data->source_directory); + TALLOC_FREE(data); return NULL; } + SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates, + struct dirsort_privates, return NULL); + return data->source_directory; } @@ -153,16 +155,17 @@ static SMB_STRUCT_DIR *dirsort_fdopendir(vfs_handle_struct *handle, data->fd = dirfd(data->source_directory); - SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates, - struct dirsort_privates, return NULL); - - if (!open_and_sort_dir(handle)) { + if (!open_and_sort_dir(handle, data)) { SMB_VFS_NEXT_CLOSEDIR(handle,data->source_directory); + TALLOC_FREE(data); /* fd is now closed. */ fsp->fh->fd = -1; return NULL; } + SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates, + struct dirsort_privates, return NULL); + return data->source_directory; } @@ -185,7 +188,7 @@ static SMB_STRUCT_DIRENT *dirsort_readdir(vfs_handle_struct *handle, /* throw away cache and re-read the directory if we've changed */ if (current_mtime > data->mtime) { - open_and_sort_dir(handle); + open_and_sort_dir(handle, data); } if (data->pos >= data->number_of_entries) { |