diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y index ad1a27b..1c212bb 100644 --- a/src/xkbcomp/parser.y +++ b/src/xkbcomp/parser.y @@ -216,6 +216,14 @@ resolve_keysym(const char *name, xkb_keysym_t *sym_rtrn) %type XkbFile XkbMapConfigList XkbMapConfig %type XkbCompositeMap +%destructor { FreeStmt((ParseCommon *) $$); } + + +/* The destructor also runs on the start symbol when the parser *succeeds*. + * The `if` here catches this case. */ +%destructor { if (!param->rtrn) FreeXkbFile($$); } +%destructor { free($$); } + %% /* @@ -770,6 +778,7 @@ parse(struct xkb_context *ctx, struct scanner *scanner, const char *map) struct parser_param param = { .scanner = scanner, .ctx = ctx, + .rtrn = NULL, }; /* @@ -799,6 +808,7 @@ parse(struct xkb_context *ctx, struct scanner *scanner, const char *map) FreeXkbFile(param.rtrn); } } + param.rtrn = NULL; } if (ret != 0) {