static void check_alignment()
{
	/*
	 * Pool always tries to allocate blocks with particular alignment.
	 * So there are potentially small gaps between allocations.  This
	 * test checks that valgrind is spotting illegal accesses to these
	 * gaps.
	 */

	int i, sum;
	struct dm_pool *p = dm_pool_create("blah", 1024);
	char *data1, *data2;
	char buffer[16];


	data1 = dm_pool_alloc_aligned(p, 1, 4);
	assert(data1);
	data2 = dm_pool_alloc_aligned(p, 1, 4);
	assert(data1);

	snprintf(buffer, sizeof(buffer), "%c", *(data1 + 1)); /* invalid read size 1 */
	dm_pool_destroy(p);
}
Exemplo n.º 2
0
void *dm_pool_alloc(struct dm_pool *p, size_t s)
{
	return dm_pool_alloc_aligned(p, s, DEFAULT_ALIGNMENT);
}