BUG: Fix memory leak in ndarray construction from strings (gh-2927)

Backports #2928.