Bug 11698 - memory leak at samba clustering
memory leak at samba clustering
Status: NEW
Product: Samba 4.1 and newer
Classification: Unclassified
Component: File services
4.3.3
All All
: P5 major
: ---
Assigned To: Samba QA Contact
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2016-01-28 08:48 UTC by crashskyshadow
Modified: 2016-01-28 11:11 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description crashskyshadow 2016-01-28 08:48:26 UTC
brl_lck not free in clustering environment. below is the code fix.

diff --git a/samba/samba-4.3.3/source3/locking/locking.c b/samba/samba-4.3.3/source3/locking/locking.c
index 7b8bc84..f8aacd3 100644
--- a/samba/samba-4.3.3/source3/locking/locking.c
+++ b/samba/samba-4.3.3/source3/locking/locking.c
@@ -139,6 +139,11 @@ bool strict_lock_default(files_struct *fsp, struct lock_struct *plock)
        }
        ret = brl_locktest(br_lck, plock);
 
+       /*fix memory leak*/
+       if (lp_clustering()) {
+               TALLOC_FREE(br_lck);
+       }
+
        if (!ret) {
                /*
                 * We got a lock conflict. Retry with rw locks to enable
@@ -188,14 +193,19 @@ NTSTATUS query_lock(files_struct *fsp,
        if (!br_lck) {
                return NT_STATUS_NO_MEMORY;
        }
-
-       return brl_lockquery(br_lck,
+       
+       /*fix memeory leak*/
+       NTSTATUS ret = brl_lockquery(br_lck,
                        psmblctx,
                        messaging_server_id(fsp->conn->sconn->msg_ctx),
                        poffset,
                        pcount,
                        plock_type,
                        lock_flav);
+       if (lp_clustering()) {
+               TALLOC_FREE(br_lck);
+       }
+       return ret;
 }
 
 static void increment_current_lock_count(files_struct *fsp,
diff --git a/samba/samba-4.3.3/source3/smbd/open.c b/samba/samba-4.3.3/source3/smbd/open.c
index 162e834..511ce02 100644
--- a/samba/samba-4.3.3/source3/smbd/open.c
+++ b/samba/samba-4.3.3/source3/smbd/open.c
@@ -1504,8 +1504,12 @@ static bool file_has_brlocks(files_struct *fsp)
        br_lck = brl_get_locks_readonly(fsp);
        if (!br_lck)
                return false;
-
-       return (brl_num_locks(br_lck) > 0);
+       /*fix memory leak*/
+       bool ret=(brl_num_locks(br_lck) > 0);
+       if (lp_clustering()) {
+               TALLOC_FREE(br_lck);
+       }
+       return ret;
 }
 
 int find_share_mode_lease(struct share_mode_data *d,
diff --git a/samba/samba-4.3.3/source3/smbd/oplock.c b/samba/samba-4.3.3/source3/smbd/oplock.c
index 4d84347..85bfddc 100644
--- a/samba/samba-4.3.3/source3/smbd/oplock.c
+++ b/samba/samba-4.3.3/source3/smbd/oplock.c
@@ -208,9 +208,18 @@ bool update_num_read_oplocks(files_struct *fsp, struct share_mode_lock *lck)
                return false;
        }
        if (brl_num_read_oplocks(br_lck) == num_read_oplocks) {
+               /*fix memory leak*/
+               if (lp_clustering()) {
+                       TALLOC_FREE(br_lck);
+               }
                return true;
        }
 
+       /*fix memory leak*/
+       if (lp_clustering()) {
+               TALLOC_FREE(br_lck);
+       }
+
        br_lck = brl_get_locks(talloc_tos(), fsp);
        if (br_lck == NULL) {
                return false;
@@ -1060,6 +1069,10 @@ static void contend_level2_oplocks_begin_default(files_struct *fsp,
        brl = brl_get_locks_readonly(fsp);
        if (brl != NULL) {
                num_read_oplocks = brl_num_read_oplocks(brl);
+               /*fix memory leak*/
+               if (lp_clustering()) {
+                       TALLOC_FREE(brl);
+               }
        }
 
        DEBUG(10, ("num_read_oplocks = %"PRIu32"\n", num_read_oplocks));