Fix up some resource leak and logic bugs in source::connect