Improve patterns for cleaning up static variables on exit/restart
In his review for legacy/trac#23524 (moved), asn says:
I feel like resetting all the global statics on
tor_free_all()
makes sense but it's all a very brittle logic. The moment someone adds a new global static in that file and doesn't know about this convention of wiping attor_free_all()
, it will introduce a bug IIUC. Furthermore, the fact that some of those vars get reset to 0 and others to 1 is kinda arbitrary (and you need to look at their definitions to see if it's correct).I wonder what we could do about
3809036
to make it better. Perhaps we should de-global those variables, put them in a struct, and initialize them in a function, then call that function from some entry-point andtor_free_all()
? That seems like a better approach but probably not so trivial. Maybe subject for a future ticket on this area?
We should indeed look for better patterns to solve this issue, since the current approach is indeed fragile.