RCSID("$Id$")
#include <freeradius-devel/util/ring_buffer.h>
+#include <freeradius-devel/fr_log.h>
#include <freeradius-devel/rad_assert.h>
#include <string.h>
fr_ring_buffer_t *rb;
rb = talloc_zero(ctx, fr_ring_buffer_t);
- if (!rb) return NULL;
+ if (!rb) {
+ fail:
+ fr_strerror_printf("Failed allocating memory.");
+ return NULL;
+ }
rb->buffer = talloc_array(rb, uint8_t, size);
if (!rb->buffer) {
talloc_free(rb);
- return NULL;
+ goto fail;
}
rb->size = size;
(void) talloc_get_type_abort(rb, fr_ring_buffer_t);
#endif
- if (rb->closed) return NULL;
+ if (rb->closed) {
+ fr_strerror_printf("Allocation request after ring buffer is closed");
+ return NULL;
+ }
/*
* We're writing to the start of the buffer, and there is
return rb->buffer + rb->write_offset;
}
+ fr_strerror_printf("No memory available in ring buffer");
return NULL;
}
*
* |....S****WE....|
*/
+ fr_strerror_printf("No memory available in ring buffer");
return NULL;
}
(void) talloc_get_type_abort(rb, fr_ring_buffer_t);
#endif
- if (rb->closed) return NULL;
+ if (rb->closed) {
+ fr_strerror_printf("Allocation request after ring buffer is closed");
+ return NULL;
+ }
/*
* Shrink the "reserved" portion of the buffer by the
return p;
}
+ fr_strerror_printf("No memory available in ring buffer");
return NULL;
}
*
* |....S****WE....|
*/
+ fr_strerror_printf("No memory available in ring buffer");
return NULL;
}
(void) talloc_get_type_abort(dst, fr_ring_buffer_t);
#endif
- if (dst->closed) return NULL;
+ if (dst->closed) {
+ fr_strerror_printf("Allocation request after ring buffer is closed");
+ return NULL;
+ }
/*
* The application hasn't reserved enough space, so we can't
* split the reservation.
*/
- if (src->reserved < move_size) return NULL;
+ if (src->reserved < move_size) {
+ fr_strerror_printf("Cannot move more data than was reserved.");
+ return NULL;
+ }
/*
* Create a new reservation.
/*
* Freeing too much, return an error.
*/
- if (size_to_free > block_size) return -1;
+ if (size_to_free > block_size) {
+ fr_strerror_printf("Cannot free more memory than exists.");
+ return -1;
+ }
/*
* Free some data from the start.