Sometimes TopologyManagerImport receives more than one endpointAdded event for the same endpoint and filter. Currently this causes it to add the endpoint multiple times to an internal list. However when the endpoint is removed, only one endpointRemoved event is triggered, one instance is removed from the list, and the other copies remain. The rest of the code treats this as the endpoint still being available, which is what the clients see as well (the import is never closed).
The patch simply adds a check so that the endpoint will not be added to the list if it's already there. It also removes empty import lists when all imports are removed, preventing a leak.