FS-10167 encore
This commit is contained in:
parent
ac3d685191
commit
e1d596d0c9
|
@ -53,6 +53,7 @@ typedef struct alloc_prefix_s {
|
|||
unsigned long size;
|
||||
unsigned char m2;
|
||||
unsigned int refs;
|
||||
unsigned int padding;
|
||||
} alloc_prefix_t;
|
||||
|
||||
#define PREFIX_SIZE sizeof(struct alloc_prefix_s)
|
||||
|
@ -780,8 +781,6 @@ static void *get_space(ks_pool_t *mp_p, const unsigned long byte_size, unsigned
|
|||
void *free_addr = NULL, *free_end;
|
||||
|
||||
size = byte_size;
|
||||
*padding = 0;
|
||||
|
||||
while ((size & (sizeof(void *) - 1)) > 0) {
|
||||
size++;
|
||||
}
|
||||
|
@ -950,18 +949,22 @@ static void *alloc_mem(ks_pool_t *mp_p, const unsigned long byte_size, ks_status
|
|||
|
||||
/* get our free space + the space for the fence post */
|
||||
addr = get_space(mp_p, size + fence + PREFIX_SIZE, &padding, error_p);
|
||||
|
||||
if (addr == NULL) {
|
||||
/* error_p set in get_space */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
write_magic((char *) addr + size + PREFIX_SIZE);
|
||||
|
||||
prefix = (alloc_prefix_t *) addr;
|
||||
prefix->m1 = PRE_MAGIC1;
|
||||
prefix->m2 = PRE_MAGIC2;
|
||||
prefix->size = size + fence + PREFIX_SIZE + padding;
|
||||
prefix->refs = 1;
|
||||
prefix->padding = padding;
|
||||
|
||||
write_magic((char *) prefix + prefix->size - padding - fence);
|
||||
|
||||
if (mp_p->mp_log_func != NULL) {
|
||||
mp_p->mp_log_func(mp_p, KS_POOL_FUNC_INCREF, prefix->size, prefix->refs, NULL, addr, 0);
|
||||
}
|
||||
|
@ -1039,7 +1042,7 @@ static int free_mem(ks_pool_t *mp_p, void *addr)
|
|||
}
|
||||
|
||||
/* find the user's magic numbers */
|
||||
ret = check_magic(addr, size - FENCE_SIZE - PREFIX_SIZE);
|
||||
ret = check_magic(prefix, prefix->size - FENCE_SIZE - prefix->padding);
|
||||
|
||||
perform_pool_cleanup_on_free(mp_p, addr);
|
||||
|
||||
|
@ -1882,7 +1885,8 @@ KS_DECLARE(void *) ks_pool_resize_ex(ks_pool_t *mp_p, void *old_addr, const unsi
|
|||
}
|
||||
|
||||
if (old_byte_size > 0) {
|
||||
ret = check_magic(old_addr, old_byte_size - FENCE_SIZE - PREFIX_SIZE);
|
||||
ret = check_magic(prefix, prefix->size - FENCE_SIZE - prefix->padding);
|
||||
|
||||
if (ret != KS_STATUS_SUCCESS) {
|
||||
if (!(mp_p->mp_flags & KS_POOL_FLAG_NO_ASSERT)) {
|
||||
abort();
|
||||
|
|
|
@ -64,7 +64,7 @@ int main(int argc, char **argv)
|
|||
|
||||
status = ks_pool_open(&pool);
|
||||
|
||||
printf("OPEN:\n");
|
||||
printf("OPEN: %p\n", (void *)pool);
|
||||
ok(status == KS_STATUS_SUCCESS);
|
||||
if (status != KS_STATUS_SUCCESS) {
|
||||
fprintf(stderr, "OPEN ERR: %d [%s]\n", err, ks_pool_strerror(status));
|
||||
|
@ -176,7 +176,7 @@ int main(int argc, char **argv)
|
|||
ks_pool_set_cleanup(pool, foo, NULL, 0, cleanup);
|
||||
|
||||
|
||||
printf("ALLOC OBJ3:\n");
|
||||
printf("ALLOC OBJ3: %p\n", (void *)pool);
|
||||
|
||||
foo = ks_pool_alloc(pool, sizeof(struct foo));
|
||||
|
||||
|
@ -188,13 +188,14 @@ int main(int argc, char **argv)
|
|||
printf("ALLOC OBJ3 [%p]:\n", (void *) foo);
|
||||
}
|
||||
|
||||
printf("CLEANUP: %p\n", (void *)pool);
|
||||
foo->x = 12;
|
||||
foo->str = strdup("This is a third test 1234 abcd; This will be called on pool clear/destroy\n");
|
||||
ks_pool_set_cleanup(pool, foo, NULL, 0, cleanup);
|
||||
|
||||
|
||||
|
||||
printf("RESIZE:\n");
|
||||
printf("RESIZE: %p\n", (void *)pool);
|
||||
|
||||
|
||||
ks_snprintf(str, bytes, "%s", STR);
|
||||
|
|
Loading…
Reference in New Issue