Here is another improvement: there should be no reason to keep the regexp busy during the overflow error processing, so release it first. By the way, is there any reason why only calls to re_search_2 are made with a busy-marked regexp buffer, not calls to re_search? Are the latter guaranteed not to be reentrant?