Fix lock race condition.

Issue:	#791
Reported by:	@infracaninophile
Fix finalization in pkg-clean.