Clean up buffers and fds on thread exit.

This patch makes the rr preload library non-optional: we use it hook
pthread_create() and to register a thread cleanup function.  Each
thread keeps a record of buffers that have been mapped on its behalf,
and the desched fd if buffering is enabled, and at thread destruction
time, the cleanup function unmaps and closes those resources.

(rr will technically function without the preload library, but will
leak resources like sieve, as before this patch.)

This patch incidentally fixes a small memory leak in the recorder and
a more serious fd leak in the replayer, which the test for this bug
exposed.