Fix bug in setNumCapabilities

We were changing n_capabilities after we had released the
Capabilities, which lead to a range of interesting crashes.  This
should fix test failures in setnumcapabilities001.