No memleaks here because in all cases when we'll have filled errormsg, we'll exit from the loop by 'goto err' command.