Case 2 could lead to a leak because your "else if" chain has no final else clause. If none of the conditions apply, sub_code will never be freed. You could just add at the end else free(sub_code); and that would take care of it.
S
StevenWh
@StevenWh