Fixed some memory leaks in capabilities