main: Add RAII to lock file

Change-Id: Idddefafcbbfeb886106d2aa9894f59aede6d1eff