summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2000-10-02 21:03:46 +0000
committerJeremy Allison <jra@samba.org>2000-10-02 21:03:46 +0000
commit2679fa315da579fbdc7dd35d3ee1cb364b85a1d9 (patch)
treecd213fbf437ed7968b16f03e3dc256f98307bef0 /source3
parente26d09685cf4aff2256adccf9b576d48fe52cc89 (diff)
downloadsamba-2679fa315da579fbdc7dd35d3ee1cb364b85a1d9.tar.gz
samba-2679fa315da579fbdc7dd35d3ee1cb364b85a1d9.tar.bz2
samba-2679fa315da579fbdc7dd35d3ee1cb364b85a1d9.zip
Memleak fix for cache code.
Jeremy. (This used to be commit 1ebe54666b0fc6f224f17036063dfe0ef7ec9147)
Diffstat (limited to 'source3')
-rw-r--r--source3/include/proto.h1
-rw-r--r--source3/smbd/close.c24
-rw-r--r--source3/smbd/fileio.c8
3 files changed, 27 insertions, 6 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index c79db02a4a..f06a0a790f 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -3368,7 +3368,6 @@ BOOL check_plaintext_password(char *user, char *old_passwd,
/*The following definitions come from smbd/close.c */
#if OLD_NTDOMAIN
-void close_filestruct(files_struct *fsp);
int close_file(files_struct *fsp, BOOL normal_close);
#endif
diff --git a/source3/smbd/close.c b/source3/smbd/close.c
index 0b7b5f794e..f71b6b04f1 100644
--- a/source3/smbd/close.c
+++ b/source3/smbd/close.c
@@ -68,11 +68,15 @@ static void check_magic(files_struct *fsp,connection_struct *conn)
Common code to close a file or a directory.
****************************************************************************/
-void close_filestruct(files_struct *fsp)
+static int close_filestruct(files_struct *fsp)
{
connection_struct *conn = fsp->conn;
+ int ret = 0;
- flush_write_cache(fsp, CLOSE_FLUSH);
+ if(flush_write_cache(fsp, CLOSE_FLUSH) == -1)
+ ret = -1;
+
+ delete_write_cache(fsp);
fsp->is_directory = False;
fsp->stat_open = False;
@@ -82,6 +86,8 @@ void close_filestruct(files_struct *fsp)
free((char *)fsp->wbmpx_ptr);
fsp->wbmpx_ptr = NULL;
}
+
+ return ret;
}
/****************************************************************************
@@ -98,10 +104,17 @@ static int close_normal_file(files_struct *fsp, BOOL normal_close)
BOOL delete_on_close = fsp->delete_on_close;
connection_struct *conn = fsp->conn;
int err = 0;
+ int err1 = 0;
remove_pending_lock_requests_by_fid(fsp);
- close_filestruct(fsp);
+ /*
+ * If we're flushing on a close we can get a write
+ * error here, we must remember this.
+ */
+
+ if (close_filestruct(fsp) == -1)
+ err1 = -1;
if (normal_close && fsp->print_file) {
print_fsp_end(fsp);
@@ -156,7 +169,10 @@ with error %s\n", fsp->fsp_name, strerror(errno) ));
file_free(fsp);
- return err;
+ if (err == -1 || err1 == -1)
+ return -1;
+ else
+ return 0;
}
/****************************************************************************
diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c
index 7fbf6e2a37..3ebc46e86b 100644
--- a/source3/smbd/fileio.c
+++ b/source3/smbd/fileio.c
@@ -186,7 +186,7 @@ ssize_t write_file(files_struct *fsp, char *data, SMB_OFF_T pos, size_t n)
* the write cache.
*/
- if ((fsp->oplock_type == EXCLUSIVE_OPLOCK) && !wcp) {
+ if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !wcp) {
setup_write_cache(fsp, st.st_size);
wcp = fsp->wcp;
}
@@ -569,6 +569,9 @@ void delete_write_cache(files_struct *fsp)
free(wcp);
fsp->wcp = NULL;
+
+ DEBUG(10,("delete_write_cache: File %s deleted write cache\n", fsp->fsp_name ));
+
}
/****************************************************************************
@@ -604,6 +607,9 @@ static BOOL setup_write_cache(files_struct *fsp, SMB_OFF_T file_size)
fsp->wcp = wcp;
allocated_write_caches++;
+ DEBUG(10,("setup_write_cache: File %s allocated write cache size %u\n",
+ fsp->fsp_name, wcp->alloc_size ));
+
return True;
}