Extract the result of get*_r before we deallocate the auxiliary buffer

Also comes with tests. This closes #8108.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
Add some extra files to .gitignore

Signed-off-by: Austin Seipp <aseipp@pobox.com>