struct ralloc_header
{
+#ifdef DEBUG
/* A canary value used to determine whether a pointer is ralloc'd. */
unsigned canary;
+#endif
struct ralloc_header *parent;
{
ralloc_header *info = (ralloc_header *) (((char *) ptr) -
sizeof(ralloc_header));
+#ifdef DEBUG
assert(info->canary == CANARY);
+#endif
return info;
}
ralloc_size(const void *ctx, size_t size)
{
void *block = calloc(1, size + sizeof(ralloc_header));
+ ralloc_header *info;
+ ralloc_header *parent;
if (unlikely(block == NULL))
return NULL;
- ralloc_header *info = (ralloc_header *) block;
- ralloc_header *parent = ctx != NULL ? get_header(ctx) : NULL;
+ info = (ralloc_header *) block;
+ parent = ctx != NULL ? get_header(ctx) : NULL;
add_child(parent, info);
+#ifdef DEBUG
info->canary = CANARY;
+#endif
return PTR_FROM_HEADER(info);
}