afc.c: fixed leaks in various functions when an invalid argument error is passed

More potential afc leaks similar to those recently merged. Memory was malloc'ed before arguments were checked, but not freed if an argument is invalid.