ntop/nDPI

how to remove the allocated memory of patricia in nDPI? (interface: ndpi_patricia_lookup)

ccworkhard opened this issue · 5 comments

When i use nDPI library, it seems a memory leak happen. When a ip packet arrives, it's just to call [add_to_ptree.isra.9], and then [ndpi_patricia_lookup], finally call [ndpi_calloc], but it never clean the old node and free its memory? Can i call some interfaces to fix the memory problem?

********* the valgrind out put*********
********* if you need more info, just say, i can provide ********
==13291== 1,612,608 bytes in 25,197 blocks are still reachable in loss record 1,514 of 1,515
==13291== at 0x4C29F73: malloc (vg_replace_malloc.c:309)
==13291== by 0x4FAD67: ndpi_calloc (ndpi_main.c:247)
==13291== by 0x539290: ndpi_patricia_lookup (ndpi_patricia.c:793)
==13291== by 0x4FB962: add_to_ptree.isra.9 (ndpi_main.c:2392)
==13291== by 0x4FB9B4: ndpi_init_ptree_ipv4.isra.10 (ndpi_main.c:2462)
==13291== by 0x508ADF: ndpi_init_detection_module (ndpi_main.c:2727)
==13291== by 0x4644AA: pcpp::NdpiParser::NdpiParser() (NdpiParser.cpp:35)
==13291== by 0x4645F3: pcpp::NdpiParser::getInstance() (NdpiParser.cpp:59)
==13291== by 0x4497E9: __static_initialization_and_destruction_0(int, int) (Flow.cpp:47)
==13291== by 0x4498BA: _GLOBAL__sub_I__ZN4pcpp4Flow13m_igmp_layersB5cxx11E (Flow.cpp:383)
==13291== by 0x54C5CC: __libc_csu_init (in /home/data/Catalog/Probe/myflowprobe/build/bin/aprobe)
==13291== by 0x68AD4E4: (below main) (in /usr/lib64/libc-2.17.so)

You must call ndpi_exit_detection_module().
Please, note that these allocations are not performed when "a ip packet arrives", but at init time.

You must call ndpi_exit_detection_module(). Please, note that these allocations are not performed when "a ip packet arrives", but at init time.

yeah, thanks. i init the dection modlue at init time, and call ndpi_exit_detection_module when the service down. But i notice the memory always continues to expand when i run this service, it will cause oom.

Then i notice the ndpi patricia always calloc memory when a packet arrives, i suppose this is the reason of oom, what do you think about it. Does it provide interface to delete the memory of ndpi internal patricia?

Then i notice the ndpi patricia always calloc memory when a packet arrives

No, it doesn't. I am pretty sure that in the patricia tree, memory is allocated only at init time. Do you have a stack proving otherwise (could you share it)? If so you are probably using the API wrongly

Then i notice the ndpi patricia always calloc memory when a packet arrives

No, it doesn't. I am pretty sure that in the patricia tree, memory is allocated only at init time. Do you have a stack proving otherwise (could you share it)? If so you are probably using the API wrongly

thanks, u are right, the memory problem is my program's another bug, the nDPI is very useful and no leak.

Glad that you find nDPI useful.
Closing