I'm using Bison to generate a parser and the lexer is written in Ragel. When I run my code with Valgrind, it gives me this output:
200,014 bytes in 2 blocks are definitely lost in loss record 139,468 of 139,600
malloc (vg_replace_malloc.c:393)
*yyparse (parser.c:1768)
*GraphQL_CParser_Parser_c_parse (graphql_c_parser_ext.c:8)
vm_call_cfunc_with_frame (vm_insnhelper.c:3268)
vm_sendish (vm_insnhelper.c:5080)
vm_exec_core (insns.def:820)
rb_vm_exec (vm.c:2374)
...
(There's more to it -- I'm calling into the parser from Ruby. The full build output is available here, for now: https://github.com/rmosolgo/graphql-ruby/actions/runs/4556195698/jobs/8036241668?pr=4410)
It points to my (generated) yyparse function, at code like this:
# else /* defined YYSTACK_RELOCATE */
/* Extend the stack our own way. */
if (YYMAXDEPTH <= yystacksize)
YYNOMEM;
yystacksize *= 2;
if (YYMAXDEPTH < yystacksize)
yystacksize = YYMAXDEPTH;
{
yy_state_t *yyss1 = yyss;
union yyalloc *yyptr =
YY_CAST (union yyalloc *,
YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
if (! yyptr)
YYNOMEM;
YYSTACK_RELOCATE (yyss_alloc, yyss);
YYSTACK_RELOCATE (yyvs_alloc, yyvs);
# undef YYSTACK_RELOCATE
if (yyss1 != yyssa)
YYSTACK_FREE (yyss1);
}
How can I address this error message from Valgrind? I'm not sure if this is a legitimate memory leak and I should find a way to free that allocated memory, or whether it's a false positive and I should suppress this message.
Is there anything I can do to debug further?
The entire generated C parser here, in case it helps: https://github.com/rmosolgo/graphql-ruby/blob/a048682e6d8468d16947ee1c80946dd23c5d91f9/graphql-c_parser/ext/graphql_c_parser_ext/parser.c
And the Bison definition is available here: https://github.com/rmosolgo/graphql-ruby/blob/a048682e6d8468d16947ee1c80946dd23c5d91f9/graphql-c_parser/ext/graphql_c_parser_ext/parser.y
Thanks for taking a look!