It seems that there's a common pattern among the various generators. Let's add a helper function for it and make use of it in cryptsetup-generator. This fixes a bunch of theoretical memleaks in error paths, since *to wasn't generally freed properly. Not thath it matters.