In main, resources were freed on the success path but not in the error path. This change ensures all allocated resources are released before returning.
In main, resources were freed on the success path but not in the error path. This change ensures all allocated resources are released before returning.