Add get_connected_ports function to obtain the list of port connections.

Also fix a memory leak in get_ports.