mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-18 11:40:50 +00:00
MINOR: sink: add helper function to deallocate sink struct
In this patch we move sink freeing logic outside of sink_deinit() function in order to create the sink_free() helper function that could be used on error paths for example.
This commit is contained in:
parent
6049a478e4
commit
5a8755681d
62
src/sink.c
62
src/sink.c
@ -771,6 +771,40 @@ void sink_rotate_file_backed_ring(const char *name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* helper function to completely deallocate a sink struct
|
||||
*/
|
||||
static void sink_free(struct sink *sink)
|
||||
{
|
||||
struct sink_forward_target *sft_next;
|
||||
|
||||
if (!sink)
|
||||
return;
|
||||
if (sink->type == SINK_TYPE_BUFFER) {
|
||||
if (sink->store) {
|
||||
size_t size = (sink->ctx.ring->buf.size + 4095UL) & -4096UL;
|
||||
void *area = (sink->ctx.ring->buf.area - sizeof(*sink->ctx.ring));
|
||||
|
||||
msync(area, size, MS_SYNC);
|
||||
munmap(area, size);
|
||||
ha_free(&sink->store);
|
||||
}
|
||||
else
|
||||
ring_free(sink->ctx.ring);
|
||||
}
|
||||
LIST_DEL_INIT(&sink->sink_list); // remove from parent list
|
||||
task_destroy(sink->forward_task);
|
||||
free_proxy(sink->forward_px);
|
||||
ha_free(&sink->name);
|
||||
ha_free(&sink->desc);
|
||||
while (sink->sft) {
|
||||
sft_next = sink->sft->next;
|
||||
ha_free(&sink->sft);
|
||||
sink->sft = sft_next;
|
||||
}
|
||||
ha_free(&sink);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse "ring" section and create corresponding sink buffer.
|
||||
*
|
||||
@ -1304,33 +1338,9 @@ static void sink_init()
|
||||
static void sink_deinit()
|
||||
{
|
||||
struct sink *sink, *sb;
|
||||
struct sink_forward_target *sft_next;
|
||||
|
||||
list_for_each_entry_safe(sink, sb, &sink_list, sink_list) {
|
||||
if (sink->type == SINK_TYPE_BUFFER) {
|
||||
if (sink->store) {
|
||||
size_t size = (sink->ctx.ring->buf.size + 4095UL) & -4096UL;
|
||||
void *area = (sink->ctx.ring->buf.area - sizeof(*sink->ctx.ring));
|
||||
|
||||
msync(area, size, MS_SYNC);
|
||||
munmap(area, size);
|
||||
ha_free(&sink->store);
|
||||
}
|
||||
else
|
||||
ring_free(sink->ctx.ring);
|
||||
}
|
||||
LIST_DELETE(&sink->sink_list);
|
||||
task_destroy(sink->forward_task);
|
||||
free_proxy(sink->forward_px);
|
||||
free(sink->name);
|
||||
free(sink->desc);
|
||||
while (sink->sft) {
|
||||
sft_next = sink->sft->next;
|
||||
free(sink->sft);
|
||||
sink->sft = sft_next;
|
||||
}
|
||||
free(sink);
|
||||
}
|
||||
list_for_each_entry_safe(sink, sb, &sink_list, sink_list)
|
||||
sink_free(sink);
|
||||
}
|
||||
|
||||
INITCALL0(STG_REGISTER, sink_init);
|
||||
|
Loading…
Reference in New Issue
Block a user