Wireshark mailing list archives
Re: [PATCH] Re: Freeing memory of se_alloc'ated object
From: ronnie sahlberg <ronniesahlberg () gmail com>
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 () gmail com> wrote:
2011/5/2 Guy Harris <guy () alum mit edu>: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 () wireshark org> Archives: http://www.wireshark.org/lists/wireshark-dev Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev mailto:wireshark-dev-request () wireshark org?subject=unsubscribe
___________________________________________________________________________ Sent via: Wireshark-dev mailing list <wireshark-dev () wireshark org> Archives: http://www.wireshark.org/lists/wireshark-dev Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev mailto:wireshark-dev-request () wireshark org?subject=unsubscribe
Current thread:
- Re: Freeing memory of se_alloc'ated object, (continued)
- Re: Freeing memory of se_alloc'ated object Guy Harris (May 01)
- Re: Freeing memory of se_alloc'ated object Max (May 01)
- Re: Freeing memory of se_alloc'ated object Guy Harris (May 01)
- [PATCH] Re: Freeing memory of se_alloc'ated object Max (May 01)
- Re: [PATCH] Re: Freeing memory of se_alloc'ated object darkjames-ws (May 02)
- Re: [PATCH] Re: Freeing memory of se_alloc'ated object Max (May 02)
- Re: [PATCH] Re: Freeing memory of se_alloc'ated object Jakub Zawadzki (May 03)
- Re: Freeing memory of se_alloc'ated object Max (May 01)
- Re: [PATCH] Re: Freeing memory of se_alloc'ated object Jeff Morriss (May 02)
- Re: [PATCH] Re: Freeing memory of se_alloc'ated object Guy Harris (May 02)
- Re: [PATCH] Re: Freeing memory of se_alloc'ated object Max (May 02)
- Re: [PATCH] Re: Freeing memory of se_alloc'ated object ronnie sahlberg (May 02)
- Re: [PATCH] Re: Freeing memory of se_alloc'ated object Max Dmitrichenko (May 02)
- Re: [PATCH] Re: Freeing memory of se_alloc'ated object Stephen Fisher (May 03)
- Re: Freeing memory of se_alloc'ated object Guy Harris (May 01)
- Re: [PATCH] Re: Freeing memory of se_alloc'ated object Jeff Morriss (May 03)
- Re: [PATCH] Re: Freeing memory of se_alloc'ated object Max (May 02)