Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] Checking address in WMEM

From: Dario Lombardo <dario.lombardo.ml@xxxxxxxxx>
Date: Thu, 26 Jan 2017 10:06:16 +0100


On Wed, Jan 25, 2017 at 6:50 PM, Evan Huus <eapache@xxxxxxxxx> wrote:
On my phone, but the short version is that there's no way to check this, and no efficient way to build it.

Evan


Looking into the code it seems to me that the routine of free_all should traverse all the allocated memory. I've written a code that mimics it, but I'm still failing to have all the addresses for some type conversions. That's the code I'm working on

// Check if 'address' belongs to the given scope.
gboolean
wmem_check_allocator_block(wmem_allocator_t* allocator, void* address)
{
    wmem_block_allocator_t *private_allocator = (wmem_block_allocator_t*)allocator->private_data;
    wmem_block_hdr_t       *cur;
    wmem_block_chunk_t     *chunk;
    void* a = WMEM_DATA_TO_CHUNK(address);

    cur = private_allocator->block_list;

    while (cur) {
        chunk = WMEM_BLOCK_TO_CHUNK(cur);
        if (a == chunk)
            return TRUE;
        cur = cur->next;
    }
    return FALSE;
}

If I allocate a block and the allocator gives me 7c40 as address, the function checks only 7c30. It looks like I'm casting/converting the addresses the wrong way.
Any idea? Does this approach sound good, or am I completely following the wrong path?

Thanks anyway.
Dario.