On Wed, Feb 05, 2020 at 12:30:24PM +0000, Laurent Fasnacht wrote: [...] > @@ -915,15 +919,14 @@ void scanner_push_buffer(void *scanner, const struct input_descriptor *indesc, > { > struct parser_state *state = yyget_extra(scanner); > YY_BUFFER_STATE b; > + struct input_descriptor *new_indesc; > > - state->indesc = xzalloc(sizeof(struct input_descriptor)); > - state->indescs[state->indesc_idx] = state->indesc; > - state->indesc_idx++; > + new_indesc = xzalloc(sizeof(struct input_descriptor)); I'd appreciate if you could split initially cleanups in separated patches. Like adding this new variable. > - memcpy(state->indesc, indesc, sizeof(*state->indesc)); > - state->indesc->data = buffer; > - state->indesc->name = NULL; > - list_add_tail(&state->indesc->list, &state->indesc_list); > + memcpy(new_indesc, indesc, sizeof(*new_indesc)); > + new_indesc->data = buffer; > + new_indesc->name = NULL; > + scanner_push_indesc(state, new_indesc); > > b = yy_scan_string(buffer, scanner); > assert(b != NULL); > @@ -940,35 +943,22 @@ void *scanner_init(struct parser_state *state) > return scanner; > } > > -static void input_descriptor_destroy(const struct input_descriptor *indesc) > -{ > - if (indesc->name) > - xfree(indesc->name); > - xfree(indesc); > -} Or removing this function, actually there is no need to check if indesc->name != NULL, so just: xfree(indesc->name); xfree(indesc); is probably fine while you are here. That will make it easier for us to track changes. Thanks!