Hello, we found many memory leaks while running kamailio-a2209018fb03d. The following is the bug report from Valgrind:
``` ==66== 10 bytes in 1 blocks are definitely lost in loss record 28 of 162 [65/169] ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x582196: yyparse (cfg.y:688) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 24 bytes in 1 blocks are definitely lost in loss record 49 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x58CAB3: yyparse (cfg.y:2181) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 128 bytes in 1 blocks are definitely lost in loss record 93 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x57580F: addstr (cfg.lex:1717) ==66== by 0x57108E: yylex (cfg.lex:1475) ==66== by 0x581BAC: yyparse (cfg.tab.c:5411) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 204 bytes in 20 blocks are definitely lost in loss record 97 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x4395D8: rval_get_str (rvalue.c:1319) ==66== by 0x59E79B: mod_f_params_pre_fixup (cfg.y:4321) ==66== by 0x599F41: yyparse (cfg.y:3769) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 256 bytes in 2 blocks are definitely lost in loss record 113 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x57580F: addstr (cfg.lex:1717) ==66== by 0x56F0B5: yylex (cfg.lex:1155) ==66== by 0x581BAC: yyparse (cfg.tab.c:5411) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 401 bytes in 15 blocks are definitely lost in loss record 118 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x285B99: ksr_locate_module (sr_module.c:457) ==66== by 0x28779F: ksr_load_module (sr_module.c:577) ==66== by 0x58A4E3: yyparse (cfg.y:2054) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 512 bytes in 4 blocks are definitely lost in loss record 124 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x57580F: addstr (cfg.lex:1717) ==66== by 0x56F266: yylex (cfg.lex:1173) ==66== by 0x581BAC: yyparse (cfg.tab.c:5411) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 896 bytes in 7 blocks are definitely lost in loss record 129 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x57580F: addstr (cfg.lex:1717) ==66== by 0x5703ED: yylex (cfg.lex:1376) ==66== by 0x581BAC: yyparse (cfg.tab.c:5411) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 1,232 bytes in 1 blocks are possibly lost in loss record 132 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x281E80: register_module (sr_module.c:264) ==66== by 0x28A20F: ksr_load_module (sr_module.c:673) ==66== by 0x58A4E3: yyparse (cfg.y:2054) ==66== by 0x1488A5: main (main.c:2512) ==66== 1,440 (928 direct, 512 indirect) bytes in 4 blocks are definitely lost in loss record 134 of 162 [6/169] ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x191C22: mk_action (route_struct.c:117) ==66== by 0x59A5F4: yyparse (cfg.y:3832) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 3,864 bytes in 4 blocks are definitely lost in loss record 144 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x281E80: register_module (sr_module.c:264) ==66== by 0x28A20F: ksr_load_module (sr_module.c:673) ==66== by 0x58A4E3: yyparse (cfg.y:2054) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 5,215 (464 direct, 4,751 indirect) bytes in 2 blocks are definitely lost in loss record 149 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x191C22: mk_action (route_struct.c:117) ==66== by 0x599723: yyparse (cfg.y:3753) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 5,400 (64 direct, 5,336 indirect) bytes in 1 blocks are definitely lost in loss record 150 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x59E378: mk_case_stm (cfg.y:4193) ==66== by 0x590762: yyparse (cfg.y:2840) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 6,784 bytes in 53 blocks are definitely lost in loss record 151 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x57580F: addstr (cfg.lex:1717) ==66== by 0x570B6A: yylex (cfg.lex:1444) ==66== by 0x581BAC: yyparse (cfg.tab.c:5411) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 9,728 bytes in 76 blocks are definitely lost in loss record 152 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x57580F: addstr (cfg.lex:1717) ==66== by 0x575754: addchar (cfg.lex:1701) ==66== by 0x56FBD6: yylex (cfg.lex:1299) ==66== by 0x581BAC: yyparse (cfg.tab.c:5411) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 31,152 (464 direct, 30,688 indirect) bytes in 2 blocks are definitely lost in loss record 158 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x191C22: mk_action (route_struct.c:117) ==66== by 0x5964F5: yyparse (cfg.y:3583) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== 95,727 (1,392 direct, 94,335 indirect) bytes in 6 blocks are definitely lost in loss record 161 of 162 ==66== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==66== by 0x191C22: mk_action (route_struct.c:117) ==66== by 0x5903A5: yyparse (cfg.y:2791) ==66== by 0x1488A5: main (main.c:2512) ==66== ==66== LEAK SUMMARY: ==66== definitely lost: 26,119 bytes in 199 blocks ==66== indirectly lost: 135,622 bytes in 285 blocks ==66== possibly lost: 1,232 bytes in 1 blocks ==66== still reachable: 609,592 bytes in 186 blocks ==66== suppressed: 0 bytes in 0 blocks ==66== Reachable blocks (those to which a pointer was found) are not shown. ```
Closed #3483 as completed.
yyparse() is used for parsing config file at start up and it allocates memory needed for the entire runtime. So it is not actually a memory leak that affects running Kamailio, chunks are allocated once and used continuously. Cleaning those chunks of memory should be done at shutdown, but it is not a easy task on a multi-process application and it is done anyhow by OS when application is no longer running.
If you want to discuss more about, email to sr-users@lists.kamailio.org or sr-dev@lists.kamailio.org