Fix possible memory leak in allocmat()