preload: code style cleanup, memleak fix

Make ioctl_record_close() accept an fd and keep the details out of wrapped
close().

Free the recorded ioctl tree after we are done with it.
preload: Move overriden read/write functions into script section

More consistent code order.
preload: factorize close functions

Just like the close functions for script and ioctl recording, add close
functions for wrapped (netlink) sockets and ioctl emulation.

Also rename ioctl_wrap_open() to ioctl_emulate_open() for consistency.