use raii to manage file descriptors