The branch, master has been updated
       via  69cca061a4e lib: Optimize file_compare
       via  79e3b1c71f5 smbd: Increase a debug level
      from  ee2fe56ba0e drepl: memory leak fix

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 69cca061a4e176c3d23f5f0771893011adafc940
Author: Volker Lendecke <[email protected]>
Date:   Wed May 1 15:34:22 2019 +0200

    lib: Optimize file_compare
    
    Triggered by two coverity false positives. Loading both files into
    talloc'ed memory seems inefficient to me. Rely on stdio to do proper
    buffering. This removes the restriction from ae95d611: "It is meant for
    small files".
    
    This is more lines, but to me it has less implicit complexity.
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Uri Simchoni <[email protected]>
    
    Autobuild-User(master): Uri Simchoni <[email protected]>
    Autobuild-Date(master): Wed Jul 17 12:45:51 UTC 2019 on sn-devel-184

commit 79e3b1c71f59591c54e87299984e50d2ffb00b6b
Author: Volker Lendecke <[email protected]>
Date:   Tue Jul 9 20:04:03 2019 +0200

    smbd: Increase a debug level
    
    This is not a real error, it happens when the share mode record is not
    around.
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Uri Simchoni <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 lib/util/util_file.c              | 55 +++++++++++++++++++++++++++++----------
 source3/locking/share_mode_lock.c |  4 +--
 2 files changed, 43 insertions(+), 16 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/util/util_file.c b/lib/util/util_file.c
index 48ee03fb5f9..5260ee9d721 100644
--- a/lib/util/util_file.c
+++ b/lib/util/util_file.c
@@ -382,22 +382,49 @@ _PUBLIC_ int fdprintf(int fd, const char *format, ...)
  */
 bool file_compare(const char *path1, const char *path2)
 {
-       size_t size1, size2;
-       char *p1, *p2;
-       TALLOC_CTX *mem_ctx = talloc_new(NULL);
-
-       p1 = file_load(path1, &size1, 0, mem_ctx);
-       p2 = file_load(path2, &size2, 0, mem_ctx);
-       if (!p1 || !p2 || size1 != size2) {
-               talloc_free(mem_ctx);
-               return false;
+       FILE *f1 = NULL, *f2 = NULL;
+       uint8_t buf1[1024], buf2[1024];
+       bool ret = false;
+
+       f1 = fopen(path1, "r");
+       if (f1 == NULL) {
+               goto done;
        }
-       if (memcmp(p1, p2, size1) != 0) {
-               talloc_free(mem_ctx);
-               return false;
+       f2 = fopen(path2, "r");
+       if (f2 == NULL) {
+               goto done;
        }
-       talloc_free(mem_ctx);
-       return true;
+
+       while (!feof(f1)) {
+               size_t n1 = fread(buf1, 1, sizeof(buf1), f1);
+               size_t n2 = fread(buf2, 1, sizeof(buf2), f2);
+
+               if (n1 != n2) {
+                       goto done;
+               }
+               if (n1 == 0) {
+                       ret = (feof(f1) && feof(f2));
+                       goto done;
+               }
+               if (memcmp(buf1, buf2, n1) != 0) {
+                       goto done;
+               }
+               if (n1 < sizeof(buf1)) {
+                       bool has_error = (ferror(f1) || ferror(f2));
+                       if (has_error) {
+                               goto done;
+                       }
+               }
+       }
+       ret = true;
+done:
+       if (f2 != NULL) {
+               fclose(f2);
+       }
+       if (f1 != NULL) {
+               fclose(f1);
+       }
+       return ret;
 }
 
 /**
diff --git a/source3/locking/share_mode_lock.c 
b/source3/locking/share_mode_lock.c
index 430d14fab4a..3c1e9a8a2cb 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -593,8 +593,8 @@ struct share_mode_lock *get_share_mode_lock(
                        smb_fname,
                        old_write_time);
                if (!NT_STATUS_IS_OK(status)) {
-                       DBG_WARNING("get_static_share_mode_data failed: %s\n",
-                                   nt_errstr(status));
+                       DBG_DEBUG("get_static_share_mode_data failed: %s\n",
+                                 nt_errstr(status));
                        TALLOC_FREE(static_share_mode_record);
                        goto fail;
                }


-- 
Samba Shared Repository

Reply via email to