Fix memory leaks in the way pcre is used.