Link manager unit test and fixes

It was unclear as to who owned the LinkInterface object once it was added to LinkManager. This would lead to double deletes and all sort of other strangeness. Wrote a unit test to better test LinkManager and then fixed the bugs that it found.

This fixes Issue #1009. It also likely fixes #1022.