r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[tprouty/samba.git] / source / locking / brlock.c
index 6713530738c6f246fa5703f5cd43d1348e31812b..228a30b7af42d45d4614f38d902a2d0ce864b7a5 100644 (file)
@@ -8,7 +8,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -17,8 +17,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /* This module implements a tdb based byte range locking service,
@@ -577,9 +576,9 @@ OR
        }
 
        /* Never get here. */
-       smb_panic("brlock_posix_split_merge\n");
+       smb_panic("brlock_posix_split_merge");
        /* Notreached. */
-       abort();
+
        /* Keep some compilers happy. */
        return 0;
 }
@@ -1309,7 +1308,7 @@ void brl_close_fnum(struct messaging_context *msg_ctx,
                        if (br_lck->num_locks) {
                                locks_copy = (struct lock_struct *)TALLOC_MEMDUP(br_lck, locks, br_lck->num_locks * sizeof(struct lock_struct));
                                if (!locks_copy) {
-                                       smb_panic("brl_close_fnum: talloc fail.\n");
+                                       smb_panic("brl_close_fnum: talloc failed");
                                }
                        } else {        
                                locks_copy = NULL;
@@ -1562,7 +1561,7 @@ static int byte_range_lock_destructor(struct byte_range_lock *br_lck)
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0, ("delete_rec returned %s\n",
                                  nt_errstr(status)));
-                       smb_panic("Could not delete byte range lock entry\n");
+                       smb_panic("Could not delete byte range lock entry");
                }
        } else {
                TDB_DATA data;
@@ -1575,7 +1574,7 @@ static int byte_range_lock_destructor(struct byte_range_lock *br_lck)
                                               TDB_REPLACE);
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0, ("store returned %s\n", nt_errstr(status)));
-                       smb_panic("Could not store byte range mode entry\n");
+                       smb_panic("Could not store byte range mode entry");
                }
        }
 
@@ -1643,9 +1642,16 @@ static struct byte_range_lock *brl_get_locks_internal(TALLOC_CTX *mem_ctx,
 
        br_lck->num_locks = data.dsize / sizeof(struct lock_struct);
        br_lck->lock_data = SMB_MALLOC_ARRAY(struct lock_struct, br_lck->num_locks);
+       if ((br_lck->num_locks != 0) && (br_lck->lock_data == NULL)) {
+               DEBUG(0, ("malloc failed\n"));
+               TALLOC_FREE(br_lck);
+               return NULL;
+       }
+
        memcpy(br_lck->lock_data, data.dptr, data.dsize);
        
        if (!fsp->lockdb_clean) {
+               int orig_num_locks = br_lck->num_locks;
 
                /* This is the first time we've accessed this. */
                /* Go through and ensure all entries exist - remove any that don't. */
@@ -1658,6 +1664,11 @@ static struct byte_range_lock *brl_get_locks_internal(TALLOC_CTX *mem_ctx,
                        return NULL;
                }
 
+               /* Ensure invalid locks are cleaned up in the destructor. */
+               if (orig_num_locks != br_lck->num_locks) {
+                       br_lck->modified = True;
+               }
+
                /* Mark the lockdb as "clean" as seen from this open file. */
                fsp->lockdb_clean = True;
        }