|
From: Igmar P. <mai...@pa...> - 2012-11-05 13:25:02
|
>> Hi,
>>
>> I've written a parser which a pretty large resulting codebase. I've still
>> got a few memory leaks. The good part : I know where it leaks.
>> The bad part : That line is a loop, where it allocates a struct, and parses
>> that on into the parser itself. Debugging is an option, but extremely time
>> consuming. What I really want is that valgrind can tell me what is the
>> start of the leaked block.
>>
>> I can enable malloc debugging, but that gives me way to much output.
>
> I don't get it - if you know where it leaks you can fix it, no? If you want to
> get memory adresses of leaked blocks (for whatever reason?), just use
> memcheck's --leak-check=full, afaik that shows the addresses and size of the
> leaked objects.
>
The loop is roughly this :
while (!parser->terminate) {
input->token = scanner_token_construct(); /* The actual call to malloc is here */
scan(&input->state, input->token);
switch (input->token->opcode) {
case SCANNER_RETCODE_EOF:
/* FIXME : This doesn't work : In case the parser doesn't expect
* this, things will blow up. Properly handle EOF situations
*/
parser_native(input->parser, 0, input->token, parser);
break;
default:
parser_native(input->parser, input->token->opcode,
input->token, parser);
break;
}
input->state.limit = input->state.cursor;
if (input->token->opcode == SCANNER_RETCODE_EOF)
break;
}
valgrind gives me :
==19316== 67 (60 direct, 7 indirect) bytes in 3 blocks are definitely lost in loss record 2 of 2
==19316== at 0x4007EFC: malloc (vg_replace_malloc.c:270)
==19316== by 0x8064DED: scanner_token_construct (parser_native.c:55)
==19316== by 0x80656FE: is_parser_native_parse_input (parser_native.c:355)
==19316== by 0x8065518: is_parser_native_parse_file (parser_native.c:278)
==19316== by 0x8049749: test1 (test-native-parser.c:26)
==19316== by 0x4022739: run_single_test (TestRun.c:818)
==19316== by 0x402250A: run_single_suite (TestRun.c:759)
==19316== by 0x4021C44: CU_run_all_tests (TestRun.c:379)
==19316== by 0x4023FD4: basic_run_all_tests (Basic.c:228)
==19316== by 0x4023D32: CU_basic_run_tests (Basic.c:90)
==19316== by 0x804A09E: main (test-native-parser.c:199)
Since parser_native() has about 300 code paths, I need to know what the content of the blocks is, so I can free the objects in the proper place.
I hope this makes things clear. I couldn't find the answer to my question in the manpage, of valgrind docs.
Regards,
Igmar
|