This patch was written by Paul Eggert back in 2005 [BZ #1285], but it was part of a much larger patch that was ultimately rejected. Patch attached.
Created attachment 4489 [details] regcomp.c: do not ignore memory allocation failure
I've applied the patch.