fix seg fault and call pipes_close_chain in demo