Fix bug in acquiring locks in clean_graph.c