pf: fix rules_counter:keepcounters test
The previous pf_krule_global leak fix was a bit too aggressive and cleaned up
the inactive tree pointer before we needed it to preserve counters. Only clean
up anchors that are entirely unused. Clean up pf_main_ruleset on pf shutdown.
PR: 289299
MFC after: 1 week
Fixes: 275ff85b25 ("pf: fix struct pf_krule_global leak")
Sponsored by: Rubicon Communications, LLC ("Netgate")
(cherry picked from commit e63534edbcd050215bc109cd89a31ba30c5ea850)