Exemplo n.º 1
0
	void* internal_realloc(void *ptr, size_t size)
	{
		if (ptr == NULL)
			return internal_alloc(size, DEFAULT_ALIGNMENT);
		if (size == 0)
			return nullptr;
		void* new_data = NULL;
		auto head = get_block_header(ptr);
		if (size>0)
			new_data = internal_alloc(size, head->alignment);
		if (!new_data) return nullptr;
		mcpy(new_data, ptr, min(size, head->total_size - sizeof(block_header) - head->alignment + 1));
		internal_free(ptr);
		return new_data;
	}
Exemplo n.º 2
0
void* malloc_intercept::internal_realloc(void *ptr, size_t size)
{
    if (ptr == NULL)
        return internal_alloc(size, DEFAULT_ALIGNMENT);

    // I don't know what size of alignment to use when realloc is called on block allocated with posix_memalign
    // Let's just preserve old alignment

    block_header* old_blk = block_by_ptr(ptr);

    void* new_data = internal_alloc(size, old_blk->alignment);
    if (new_data == NULL)
        return NULL;

    memcpy(new_data, ptr, std::min(size, old_blk->data_size));

    internal_free(ptr);

    return new_data;
}