regcomp.c: Don't write to freed memory

This commit moves code in two places that may have freed memory just
before writing to it, so that the writing happens before the freeing.

It seems not worth the extra test if we are going to free this memory
before actually doing the write.

This bug was found by valgrind