rc: fix wrong free() call

Also add some tests for rc file read/write.