fix memory leaks with regmatch