fixed double free error and Invalid read or write error