networkd: fix use-after-free

Free networks before links (the reverse of creation order).
networkd: link - fix memory leak