fix invalid free

Thanks To DaveDavenport