Skip to content

Commit 788433b

Browse files
Leonardo Alminanascne59
authored andcommitted
task: exposed internal function to improve testing
Additionally the destructor now works with partially initialized instances Signed-off-by: Leonardo Alminana <[email protected]>
1 parent 428b288 commit 788433b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

include/fluent-bit/flb_task.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ int flb_task_running_count(struct flb_config *config);
127127
int flb_task_running_print(struct flb_config *config);
128128
int flb_task_map_get_task_id(struct flb_config *config);
129129

130+
struct flb_task *task_alloc(struct flb_config *config);
131+
130132
struct flb_task *flb_task_create(uint64_t ref_id,
131133
const char *buf,
132134
size_t size,

src/flb_task.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ int flb_task_retry_clean(struct flb_task *task, struct flb_output_instance *ins)
238238
}
239239

240240
/* Allocate an initialize a basic Task structure */
241-
static struct flb_task *task_alloc(struct flb_config *config)
241+
struct flb_task *task_alloc(struct flb_config *config)
242242
{
243243
int task_id;
244244
struct flb_task *task;
@@ -491,22 +491,30 @@ void flb_task_destroy(struct flb_task *task, int del)
491491
}
492492

493493
/* Unlink and release task */
494-
mk_list_del(&task->_head);
494+
if (!mk_list_entry_is_orphan(&task->_head)) {
495+
mk_list_del(&task->_head);
496+
}
495497

496498
/* destroy chunk */
497-
flb_input_chunk_destroy(task->ic, del);
499+
if (task->ic != NULL) {
500+
flb_input_chunk_destroy(task->ic, del);
501+
}
498502

499503
/* Remove 'retries' */
500504
mk_list_foreach_safe(head, tmp, &task->retries) {
501505
retry = mk_list_entry(head, struct flb_task_retry, _head);
506+
502507
flb_task_retry_destroy(retry);
503508
}
504509

505-
flb_input_chunk_set_limits(task->i_ins);
510+
if (task->i_ins != NULL) {
511+
flb_input_chunk_set_limits(task->i_ins);
512+
}
506513

507-
if (task->event_chunk) {
514+
if (task->event_chunk != NULL) {
508515
flb_event_chunk_destroy(task->event_chunk);
509516
}
517+
510518
flb_free(task);
511519
}
512520

0 commit comments

Comments
 (0)