Fix freeing an invalid pointer