]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: use fh_[get|set]_refcount()
authorRalph Boehme <slow@samba.org>
Mon, 28 Sep 2020 08:37:36 +0000 (10:37 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 09:08:30 +0000 (09:08 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/close.c
source3/smbd/files.c
source3/smbd/open.c

index 92f122d8e3d187403b44fd4fa1c7ee6ef058bd17..a0d05570da226563049cf946315499f6ff834a7f 100644 (file)
@@ -799,7 +799,7 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp,
           the same handle we only have one share mode. Ensure we only remove
           the share mode on the last close. */
 
-       if (fsp->fh->ref_count == 1) {
+       if (fh_get_refcount(fsp->fh) == 1) {
                /* Should we return on error here... ? */
                tmp = close_remove_share_mode(fsp, close_type);
                status = ntstatus_keeperror(status, tmp);
index 53775ce3cab57fc300ce2e6b691f31267ebbbf46..be45cc450f080195df61f7b55b578b8a444c6e31 100644 (file)
@@ -56,7 +56,7 @@ NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
        fsp->fsp_flags.use_ofd_locks = false;
 #endif
 
-       fsp->fh->ref_count = 1;
+       fh_set_refcount(fsp->fh, 1);
        fsp_set_fd(fsp, -1);
 
        fsp->fnum = FNUM_FIELD_INVALID;
@@ -573,10 +573,11 @@ void fsp_free(files_struct *fsp)
 
        TALLOC_FREE(fsp->fake_file_handle);
 
-       if (fsp->fh->ref_count == 1) {
+       if (fh_get_refcount(fsp->fh) == 1) {
                TALLOC_FREE(fsp->fh);
        } else {
-               fsp->fh->ref_count--;
+               size_t new_refcount = fh_get_refcount(fsp->fh) - 1;
+               fh_set_refcount(fsp->fh, new_refcount);
        }
 
        if (fsp->lease != NULL) {
@@ -787,13 +788,16 @@ NTSTATUS dup_file_fsp(
        uint32_t create_options,
        files_struct *to)
 {
+       size_t new_refcount;
+
        /* this can never happen for print files */
        SMB_ASSERT(from->print_file == NULL);
 
        TALLOC_FREE(to->fh);
 
        to->fh = from->fh;
-       to->fh->ref_count++;
+       new_refcount = fh_get_refcount(to->fh) + 1;
+       fh_set_refcount(to->fh, new_refcount);
 
        to->file_id = from->file_id;
        to->initial_allocation_size = from->initial_allocation_size;
index 4d29da5659a45912dbb4f7bcac504b67c32b5fbe..bf14f5dd4544f2ec4594b54a092d8fa7b71f1bad 100644 (file)
@@ -854,7 +854,7 @@ NTSTATUS fd_close(files_struct *fsp)
                 */
                return NT_STATUS_OK;
        }
-       if (fsp->fh->ref_count > 1) {
+       if (fh_get_refcount(fsp->fh) > 1) {
                return NT_STATUS_OK; /* Shared handle. Only close last reference. */
        }