Hi,
I noticed a small typo in the patch.
prev = palloc((m + n) * sizeof(char));
line should look like
prev = palloc(2 * m * sizeof(char));
instead.
Regards.