Sort ptr_vector using its own sort() method.

This also fixes memory leak via nested calls of release().

Change-Id: I3ba90901366319bb3ee870903130042b375f733c