On Wed, 14 Feb 2024 18:40:13 +0100 Pierre Gondois <pierre.gondois@xxxxxxx> wrote: > --- a/tracecmd/trace-split.c > +++ b/tracecmd/trace-split.c > @@ -55,13 +55,10 @@ struct handle_list { > struct list_head list; > const char *name; > int index; > - struct tracecmd_input *handle; > + struct tracecmd_input *handle; > > /* Identify the top instance in the input trace. */ > bool was_top_instance; > - > - /* Identify the top instance in each output trace. */ > - bool is_top_instance; > }; > > static struct list_head handle_list; > @@ -120,6 +117,51 @@ static void free_handles(struct list_head *list) > } > } > > +static struct list_head inst_list; > + > +struct inst_list { > + struct list_head list; > + const char *name; > + struct handle_list *handle; > + > + /* Identify the top instance in the input trace. */ > + bool was_top_instance; > + > + /* Identify the top instance in the output trace. */ > + bool is_top_instance; > +}; > + > +static void free_inst(struct list_head *list) > +{ > + struct inst_list *item; > + > + while (!list_empty(list)) { > + item = container_of(list->next, struct inst_list, list); > + list_del(&item->list); > + free((char *)item->name); > + free(item); > + } Nit, the above could be simplified as: struct inst_list *item, *n; list_for_each_entry_safe(item, n, head, list) { list_del(&item->list); free((char *)item->name); free(item); } That way you don't need to deal with "container_of()". > +} > +