}
/* no conflicts - add it to the list of locks */
- locks = (struct lock_struct *)SMB_REALLOC(locks, (br_lck->num_locks + 1) * sizeof(*locks));
+ locks = talloc_realloc(br_lck, locks, struct lock_struct,
+ (br_lck->num_locks + 1));
if (!locks) {
status = NT_STATUS_NO_MEMORY;
goto fail;
existing POSIX lock range into two, and add our lock,
so we need at most 2 more entries. */
- tp = SMB_MALLOC_ARRAY(struct lock_struct, (br_lck->num_locks + 2));
+ tp = talloc_array(br_lck, struct lock_struct, br_lck->num_locks + 2);
if (!tp) {
return NT_STATUS_NO_MEMORY;
}
/* Do any Windows flavour locks conflict ? */
if (brl_conflict(curr_lock, plock)) {
/* No games with error messages. */
- SAFE_FREE(tp);
+ TALLOC_FREE(tp);
/* Remember who blocked us. */
plock->context.smblctx = curr_lock->context.smblctx;
return NT_STATUS_FILE_LOCK_CONFLICT;
if (brl_conflict_posix(curr_lock, plock)) {
/* Can't block ourselves with POSIX locks. */
/* No games with error messages. */
- SAFE_FREE(tp);
+ TALLOC_FREE(tp);
/* Remember who blocked us. */
plock->context.smblctx = curr_lock->context.smblctx;
return NT_STATUS_FILE_LOCK_CONFLICT;
plock->context.smblctx = 0xFFFFFFFFFFFFFFFFLL;
if (errno_ret == EACCES || errno_ret == EAGAIN) {
- SAFE_FREE(tp);
+ TALLOC_FREE(tp);
status = NT_STATUS_FILE_LOCK_CONFLICT;
goto fail;
} else {
- SAFE_FREE(tp);
+ TALLOC_FREE(tp);
status = map_nt_error_from_unix(errno);
goto fail;
}
/* If we didn't use all the allocated size,
* Realloc so we don't leak entries per lock call. */
if (count < br_lck->num_locks + 2) {
- tp = (struct lock_struct *)SMB_REALLOC(tp, count * sizeof(*locks));
+ tp = talloc_realloc(br_lck, tp, struct lock_struct, count);
if (!tp) {
status = NT_STATUS_NO_MEMORY;
goto fail;
}
br_lck->num_locks = count;
- SAFE_FREE(br_lck->lock_data);
+ TALLOC_FREE(br_lck->lock_data);
br_lck->lock_data = tp;
locks = tp;
br_lck->modified = True;
existing POSIX lock range into two, so we need at most
1 more entry. */
- tp = SMB_MALLOC_ARRAY(struct lock_struct, (br_lck->num_locks + 1));
+ tp = talloc_array(br_lck, struct lock_struct, br_lck->num_locks + 1);
if (!tp) {
DEBUG(10,("brl_unlock_posix: malloc fail\n"));
return False;
if (lock->lock_flav == WINDOWS_LOCK) {
/* Do any Windows flavour locks conflict ? */
if (brl_conflict(lock, plock)) {
- SAFE_FREE(tp);
+ TALLOC_FREE(tp);
return false;
}
/* Just copy the Windows lock into the new array. */
if (!overlap_found) {
/* Just ignore - no change. */
- SAFE_FREE(tp);
+ TALLOC_FREE(tp);
DEBUG(10,("brl_unlock_posix: No overlap - unlocked.\n"));
return True;
}
/* Realloc so we don't leak entries per unlock call. */
if (count) {
- tp = (struct lock_struct *)SMB_REALLOC(tp, count * sizeof(*locks));
+ tp = talloc_realloc(br_lck, tp, struct lock_struct, count);
if (!tp) {
DEBUG(10,("brl_unlock_posix: realloc fail\n"));
return False;
}
} else {
/* We deleted the last lock. */
- SAFE_FREE(tp);
+ TALLOC_FREE(tp);
tp = NULL;
}
LEVEL2_CONTEND_POSIX_BRL);
br_lck->num_locks = count;
- SAFE_FREE(br_lck->lock_data);
+ TALLOC_FREE(br_lck->lock_data);
locks = tp;
br_lck->lock_data = tp;
br_lck->modified = True;
/****************************************************************************
Ensure this set of lock entries is valid.
****************************************************************************/
-static bool validate_lock_entries(unsigned int *pnum_entries, struct lock_struct **pplocks,
+static bool validate_lock_entries(TALLOC_CTX *mem_ctx,
+ unsigned int *pnum_entries, struct lock_struct **pplocks,
bool keep_disconnected)
{
unsigned int i;
struct lock_struct *new_lock_data = NULL;
if (num_valid_entries) {
- new_lock_data = SMB_MALLOC_ARRAY(struct lock_struct, num_valid_entries);
+ new_lock_data = talloc_array(
+ mem_ctx, struct lock_struct,
+ num_valid_entries);
if (!new_lock_data) {
DEBUG(3, ("malloc fail\n"));
return False;
}
}
- SAFE_FREE(*pplocks);
+ TALLOC_FREE(*pplocks);
*pplocks = new_lock_data;
*pnum_entries = num_valid_entries;
}
/* In a traverse function we must make a copy of
dbuf before modifying it. */
- locks = (struct lock_struct *)memdup(value.dptr, value.dsize);
+ locks = (struct lock_struct *)talloc_memdup(
+ talloc_tos(), value.dptr, value.dsize);
if (!locks) {
return -1; /* Terminate traversal. */
}
/* Ensure the lock db is clean of entries from invalid processes. */
- if (!validate_lock_entries(&num_locks, &locks, true)) {
- SAFE_FREE(locks);
+ if (!validate_lock_entries(talloc_tos(), &num_locks, &locks, true)) {
+ TALLOC_FREE(locks);
return -1; /* Terminate traversal */
}
}
}
- SAFE_FREE(locks);
+ TALLOC_FREE(locks);
return 0;
}
static int byte_range_lock_destructor(struct byte_range_lock *br_lck)
{
byte_range_lock_flush(br_lck);
- SAFE_FREE(br_lck->lock_data);
return 0;
}
br_lck->num_locks = data.dsize / sizeof(struct lock_struct);
if (br_lck->num_locks != 0) {
- br_lck->lock_data = SMB_MALLOC_ARRAY(struct lock_struct,
- br_lck->num_locks);
+ br_lck->lock_data = talloc_array(
+ br_lck, struct lock_struct, br_lck->num_locks);
if (br_lck->lock_data == NULL) {
DEBUG(0, ("malloc failed\n"));
TALLOC_FREE(br_lck);
* So we need to clean the disconnected brl entry.
*/
- if (!validate_lock_entries(&br_lck->num_locks,
+ if (!validate_lock_entries(br_lck, &br_lck->num_locks,
&br_lck->lock_data, false)) {
- SAFE_FREE(br_lck->lock_data);
TALLOC_FREE(br_lck);
return NULL;
}