if (parent) {
/* Get stack from parent. The stack itself is allocated from the
- parent. */
+ parent (but does not consume parent's own stack). */
e = silc_stack_ref_stack(parent, stack_size, &si, &bsize);
if (!e)
return NULL;
- /* Allocate stack from the parent */
+ /* Allocate stack from the returned stack. We allocate ourselves from
+ our own stack. */
stack = silc_stack_alloc_block(parent, e, 1, sizeof(*stack));
if (!stack) {
silc_stack_unref_stack(parent, e);
stack->lock = parent->lock;
silc_list_init(stack->stacks, struct SilcStackDataEntryStruct, next);
- /* Allocate stack frames from the parent */
- stack->frames = silc_stack_alloc_block(parent, e, SILC_STACK_BLOCK_NUM,
+ /* Allocate stack frames from the stack itself */
+ stack->frames = silc_stack_alloc_block(stack, e, SILC_STACK_BLOCK_NUM,
sizeof(*stack->frames));
if (!stack->frames) {
silc_stack_unref_stack(parent, e);
SILC_ST_DEBUG(("Allocating %d bytes from %p", size, stack));
if (silc_unlikely(!size)) {
- SILC_LOG_ERROR(("Allocation by zero (0)"));
+ SILC_LOG_DEBUG(("Allocation by zero (0)"));
+ silc_set_errno_nofail(SILC_ERR_ZERO_ALLOCATION);
SILC_STACK_STAT(stack, num_errors, 1);
return NULL;
}
if (silc_unlikely(size > SILC_STACK_MAX_ALLOC)) {
- SILC_LOG_ERROR(("Allocating too much"));
+ SILC_LOG_DEBUG(("Allocating too much"));
+ silc_set_errno_nofail(SILC_ERR_TOO_LARGE_ALLOCATION);
SILC_STACK_STAT(stack, num_errors, 1);
if (stack->oom_handler)
stack->oom_handler(stack, stack->oom_context);
si++;
}
if (silc_unlikely(si >= SILC_STACK_BLOCK_NUM)) {
- SILC_LOG_ERROR(("Allocating too large block"));
+ SILC_LOG_DEBUG(("Allocating too large block"));
+ silc_set_errno_nofail(SILC_ERR_TOO_LARGE_ALLOCATION);
SILC_STACK_STAT(stack, num_errors, 1);
if (stack->oom_handler)
stack->oom_handler(stack, stack->oom_context);
SILC_ST_DEBUG(("Reallocating %d bytes (%d) from %p", size, old_size, stack));
if (silc_unlikely(!size || !old_size)) {
- SILC_LOG_ERROR(("Allocation by zero (0)"));
+ SILC_LOG_DEBUG(("Allocation by zero (0)"));
+ silc_set_errno_nofail(SILC_ERR_ZERO_ALLOCATION);
SILC_STACK_STAT(stack, num_errors, 1);
return NULL;
}
if (silc_unlikely(size > SILC_STACK_MAX_ALLOC)) {
- SILC_LOG_ERROR(("Allocating too much"));
+ SILC_LOG_DEBUG(("Allocating too much"));
+ silc_set_errno_nofail(SILC_ERR_TOO_LARGE_ALLOCATION);
SILC_STACK_STAT(stack, num_errors, 1);
if (stack->oom_handler)
stack->oom_handler(stack, stack->oom_context);
if (stack->stack->data[si]->bytes_left + old_size +
((unsigned char *)ptr - (unsigned char *)sptr) != bsize) {
SILC_LOG_DEBUG(("Cannot reallocate"));
+ silc_set_errno_nofail(SILC_ERR_INVALID_ARGUMENT);
SILC_STACK_STAT(stack, num_errors, 1);
return NULL;
}
}
SILC_LOG_DEBUG(("Cannot reallocate in this block"));
+ silc_set_errno_reason_nofail(SILC_ERR_TOO_LARGE_ALLOCATION,
+ "Cannot reallocate in this memory block");
SILC_STACK_STAT(stack, num_errors, 1);
return NULL;
}