vec: add missing out-of-memory check

Closes #19305