Fix #5166
Merge pull request #5168 from magistere/sparse-memerror

Fix #5166