Dummynet PIE AQM uses callout function to calculate drop probability periodically. When a queue managed by PIE is being destroyed, the callout function should be stopped and the allocated memory should be freed.
The current code free the allocated memory when callout_stop() return non-zero. However, sometimes callout_stop() returns non-zero ( I guess when the callout function is about to be called) and this race cases the callout to use memory space that has already been freed.
Based on truckman (Don Lewis) suggestions, we solved this problem by removing memory freeing code and race conditions checking from calculate_drop_prob() and adding pie_callout_cleanup() callout function which does mtx destroying and memory freeing.
In aqm_pie_cleanup(), instead of using callout_stop(), we reset aqm_pie_callout to call pie_callout_cleanup() in next 1us. This stops the scheduled calculate_drop_prob() callout and call pie_callout_cleanup() which does memory freeing.