[PATCH] s3: Fix unrequired double condition check
Swen Schillig
swen at vnet.ibm.com
Mon Apr 30 08:23:53 UTC 2018
Please review and push if happy.
This is a style-updated (like README.Coding updates) version
of an earlier version which already got an RB+ by Andreas.
Cheers Swen
-------------- next part --------------
From 6506a1495f0433874fbf3561ec483ea05cba80e4 Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at vnet.ibm.com>
Date: Mon, 5 Mar 2018 13:32:02 +0100
Subject: [PATCH] s3: Fix unrequired double condition check
Minor cleanup removing an repeated condition check and
replacing a goto by an early return.
Signed-off-by: Swen Schillig <swen at vnet.ibm.com>
---
source3/smbd/dir.c | 58 ++++++++++++++++++++++++++----------------------------
1 file changed, 28 insertions(+), 30 deletions(-)
diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c
index 8bb66b81936..bbd8d0cb429 100644
--- a/source3/smbd/dir.c
+++ b/source3/smbd/dir.c
@@ -1772,21 +1772,22 @@ static struct smb_Dir *OpenDir_fsp(TALLOC_CTX *mem_ctx, connection_struct *conn,
const char *mask,
uint32_t attr)
{
- struct smb_Dir *dirp = talloc_zero(mem_ctx, struct smb_Dir);
+ struct smb_Dir *dirp = NULL;
struct smbd_server_connection *sconn = conn->sconn;
- if (!dirp) {
- goto fail;
- }
-
if (!fsp->is_directory) {
errno = EBADF;
- goto fail;
+ return NULL;
}
if (fsp->fh->fd == -1) {
errno = EBADF;
- goto fail;
+ return NULL;
+ }
+
+ dirp = talloc_zero(mem_ctx, struct smb_Dir);
+ if (!dirp) {
+ return NULL;
}
dirp->conn = conn;
@@ -1804,42 +1805,39 @@ static struct smb_Dir *OpenDir_fsp(TALLOC_CTX *mem_ctx, connection_struct *conn,
dirp->dir_smb_fname = cp_smb_filename(dirp, fsp->fsp_name);
if (!dirp->dir_smb_fname) {
errno = ENOMEM;
- goto fail;
+ TALLOC_FREE(dirp);
+ return NULL;
}
dirp->dir = SMB_VFS_FDOPENDIR(fsp, mask, attr);
- if (dirp->dir != NULL) {
- dirp->fsp = fsp;
- } else {
- DEBUG(10,("OpenDir_fsp: SMB_VFS_FDOPENDIR on %s returned "
- "NULL (%s)\n",
- dirp->dir_smb_fname->base_name,
- strerror(errno)));
- if (errno != ENOSYS) {
- goto fail;
- }
- }
-
if (dirp->dir == NULL) {
- /* FDOPENDIR is not supported. Use OPENDIR instead. */
+ DBG_DEBUG("OpenDir_fsp: SMB_VFS_FDOPENDIR on %s returned "
+ "NULL (%s)\n",
+ dirp->dir_smb_fname->base_name,
+ strerror(errno));
+
+ if (errno == ENOSYS) {
+ TALLOC_FREE(dirp);
+ /* FDOPENDIR is not supported. Use OPENDIR instead. */
+ return open_dir_safely(mem_ctx,
+ conn,
+ fsp->fsp_name,
+ mask,
+ attr);
+ }
TALLOC_FREE(dirp);
- return open_dir_safely(mem_ctx,
- conn,
- fsp->fsp_name,
- mask,
- attr);
+ return NULL;
}
+ dirp->fsp = fsp;
+
if (sconn && !sconn->using_smb2) {
sconn->searches.dirhandles_open++;
}
+
talloc_set_destructor(dirp, smb_Dir_destructor);
return dirp;
-
- fail:
- TALLOC_FREE(dirp);
- return NULL;
}
--
2.14.3
More information about the samba-technical
mailing list