Wireshark-dev: Re: [Wireshark-dev] [PATCH] Re: Freeing memory of se_alloc'ated object

From: ronnie sahlberg <ronniesahlberg@xxxxxxxxx>
Date: Tue, 3 May 2011 10:20:26 +1000
I think registering a destructor for an allocated is very useful, but
it would be very uncommon.
Most allocations never need a destructur, so it shouldnt be made
mandatory in the allocation functions.

So instead of creating a new API for allocations with a destructor I
would suggest adding a new _add_destructor call instead.
That way you can add destructors to existing objects after they are
allocated, post allocation time.


something like :

    object = se_alloc(...);
    se_set_emem_destructor(object,  void (*your_callback)(void
*object), void *private_data);


Then this can just add the destructor to a linked list of
struct se_destructors {
    struct se_destructors *next;
    void *object;
    void *private_data;
    void (*callback)(void *object, void *private_data);
};


I threw a private_data pointer in there too.
Once you have callbacks you almost always enbd up wanting to pass data
like this to it too.


Then when before releasing all the se_ memory,   just have it walk the
list of callbacks and invoke them in turn first.

regards
ronnie sahlberg



On Tue, May 3, 2011 at 8:31 AM, Max <dmitrmax@xxxxxxxxx> wrote:
> 2011/5/2 Guy Harris <guy@xxxxxxxxxxxx>:
>>
>> A separate "cleanup" routine, called when the capture is closed, *before* the se_allocated memory is freed, might be useful...
>
> Do you mean separate as global? I.e. with setup code like
>
>  register_se_cleanup_callback(my_module_cb);
>
> ?
>
> --
>  Max
> ___________________________________________________________________________
> Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
> Archives:    http://www.wireshark.org/lists/wireshark-dev
> Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
>             mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe
>