ndpiReader.c memory leak problem
I think we need to free flow after ndpi_tdelete()
before
while (ndpi_thread_info[thread_id].num_idle_flows > 0)
ndpi_tdelete(ndpi_thread_info[thread_id].idle_flows[--ndpi_thread_info[thread_id].num_idle_flows],
&ndpi_thread_info[thread_id].ndpi_flows_root[ndpi_thread_info[thread_id].idle_scan_idx], node_cmp);
after
while (ndpi_thread_info[thread_id].num_idle_flows > 0) {
ndpi_tdelete(ndpi_thread_info[thread_id].idle_flows[ndpi_thread_info[thread_id].num_idle_flows],
&ndpi_thread_info[thread_id].ndpi_flows_root[ndpi_thread_info[thread_id].idle_scan_idx], node_cmp);
ndpi_free(ndpi_thread_info[thread_id].idle_flows[--ndpi_thread_info[thread_id].num_idle_flows])
}
Thanks.
@kYroL01
you misunderstand what I mean, ha
need to free flow itself
like free(ndpi_thread_info[thread_id].idle_flows[--ndpi_thread_info[thread_id].num_idle_flows]); not free_ndpi_flow(ndpi_thread_info[thread_id].idle_flows[--ndpi_thread_info[thread_id].num_idle_flows])
Well... https://github.com/ntop/nDPI/blob/dev/example/ndpiReader.c#L593
An idle flow is a ndpi_flow and that function do the job. Maybe I must add ndpi_free(ndpi_thread_info[thread_id].idle_flows[--ndpi_thread_info[thread_id].num_idle_flows])
yes, I have tested it,
I watched the free memory was getting less and less if didn't free flow.
Yes I did a test too and I confirm what u say. But I also think that is necessary both functions. I push a commit.
I think you did call free_ndpi_flow() here
https://github.com/ntop/nDPI/blob/dev/example/ndpiReader.c#L687
no need to call again, ha
You have to understand that many part of the code are not written to us and are inherit from an old project. So I also need a better inspection of the code. I'm watching better and do a commit. Thanks for suggestion.
It's ok, you're welcome.
@kYroL01
sorry, have to remind you
--ndpi_thread_info[thread_id].num_idle_flows must be done after all stuff. otherwise you just free the next idle flow.
ndpi_tdelete(ndpi_thread_info[thread_id].idle_flows[--ndpi_thread_info[thread_id].num_idle_flows], &ndpi_thread_info[thread_id].ndpi_flows_root[ndpi_thread_info[thread_id].idle_scan_idx], node_cmp);
/* free the memory associated to idle flow in "idle_flows" - (see struct reader thread)*/
free_ndpi_flow(ndpi_thread_info[thread_id].idle_flows[ndpi_thread_info[thread_id].num_idle_flows]);
ndpi_free(ndpi_thread_info[thread_id].idle_flows[ndpi_thread_info[thread_id].num_idle_flows]);
}
@u8906250 can you please send a pull request instead of bits and pieces. This would allow us to better evaluate your contribution. Thanks
really! I try.
I never use pull request function before.
Oh, I was wrong
"--ndpi_thread_info[thread_id].num_idle_flows" is ok
I am used to put "--" at the rear like "ndpi_thread_info[thread_id].num_idle_flows--", so I get a little confused, ha
sorry about that
Exactly... is correct
Hello! Instead of using two functions "ndpi_flow_freer" and "ndpi_free" in one place, you can use already defined function "ndpi_flow_freer", that has already included these two functions. Logically, both variants are the same, but my variant little pretty.
@mzhumakhanov I'm completely agree with you. Is a must-do-do thing that I need to change but soon a little refactory will be done. Thank you!