This looks right, though you probably should set elts to NULL afterwards.