Fix memory leaks in the Security namespace