From patchwork Mon Feb 25 02:00:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Goldstein X-Patchwork-Id: 222818 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B41692C0297 for ; Mon, 25 Feb 2013 13:01:36 +1100 (EST) Received: from localhost ([::1]:60937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9nNn-000526-0A for incoming@patchwork.ozlabs.org; Sun, 24 Feb 2013 21:01:35 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9nN3-00034I-4Y for qemu-devel@nongnu.org; Sun, 24 Feb 2013 21:00:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U9nN0-0003Op-3W for qemu-devel@nongnu.org; Sun, 24 Feb 2013 21:00:48 -0500 Received: from mail-ye0-f180.google.com ([209.85.213.180]:65154) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9nMz-0003Oe-V7 for qemu-devel@nongnu.org; Sun, 24 Feb 2013 21:00:46 -0500 Received: by mail-ye0-f180.google.com with SMTP id m9so108263yen.25 for ; Sun, 24 Feb 2013 18:00:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=lHRy38hp8cW+zYYBCTBLplmk3WWiSwAYRtDvtB1s+Dk=; b=Go9KrZpxZwXOejAo7q/U35iflc6HA2LDccujUmScAVsBCTsUqzi3dnoHXwJ9/v2qMP pLiB20/TMk6e2dCC+nfpE8LB2LfX5d+huAZrNIzdCx//6WR+Wxmd3bFwqVGtuLE6qUOq 9AFti8x1b54U3jigv+eJTPenji7FxLOlLIOD2ZmSpuIWuteWrOTCOnA152M5e46+u/9i 0bZ/jyil42xS1TBasqGjogw5fQzcjSoXXa2uhcjtraJqoJGpoqp5BQvTFBXLA5zbw9jf imQI+E/jcGGJMnpxzZvIqKtcsCzcuI/T5sUdJW56SKJncQuHUS4b4grCtyW/sa+7Fysy NcRA== X-Received: by 10.100.77.6 with SMTP id z6mr3521678ana.17.1361757645280; Sun, 24 Feb 2013 18:00:45 -0800 (PST) Received: from localhost.localdomain (c-68-62-173-137.hsd1.al.comcast.net. [68.62.173.137]) by mx.google.com with ESMTPS id s34sm22916600yhe.9.2013.02.24.18.00.44 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 24 Feb 2013 18:00:44 -0800 (PST) From: Doug Goldstein To: qemu-devel@nongnu.org Date: Sun, 24 Feb 2013 20:00:20 -0600 Message-Id: <1361757620-23318-3-git-send-email-cardoe@cardoe.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1361757620-23318-1-git-send-email-cardoe@cardoe.com> References: <1361757620-23318-1-git-send-email-cardoe@cardoe.com> X-Gm-Message-State: ALoCoQmZVXF5FevzQcna/EInCqA9cYllulA+hs4b7s9cS/jC8sSOBKg9xczcp6BJQUGWpBAtDuHI X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.213.180 Cc: Anthony Liguori , Corey Bryant , Doug Goldstein , Richa Marwaha Subject: [Qemu-devel] [PATCH 2/2] bridge helper: unified error cleanup for parse_acl_file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Handle errors and cleanup from the error in a unified place for parse_acl_file(). Signed-off-by: Doug Goldstein CC: Anthony Liguori CC: Richa Marwaha CC: Corey Bryant TO: qemu-devel@nongnu.org --- qemu-bridge-helper.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index b8771a3..d95e760 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -96,6 +96,9 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) FILE *f; char line[4096]; ACLRule *acl_rule; + struct dirent **include_list = NULL; + int i, include_count = 0; + char *conf_file = NULL; f = fopen(filename, "r"); if (f == NULL) { @@ -105,9 +108,6 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) while (fgets(line, sizeof(line), f) != NULL) { char *ptr = line; char *cmd, *arg, *argend; - struct dirent **include_list = NULL; - int i, include_count; - char *conf_file; while (isspace(*ptr)) { ptr++; @@ -126,9 +126,8 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) if (arg == NULL) { fprintf(stderr, "Invalid config line:\n %s\n", line); - fclose(f); errno = EINVAL; - return -1; + goto cleanup; } *arg = 0; @@ -167,8 +166,7 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) if (include_count < 0) { fprintf(stderr, "Unable to retrieve conf files from '%s': %s\n", arg, strerror(errno)); - fclose(f); - return -1; + goto cleanup; } for (i = 0; i < include_count; i++) { @@ -177,9 +175,8 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) fprintf(stderr, "Failed to allocate memory for " "file path: %s/%s\n", arg, include_list[i]->d_name); - fclose(f); errno = ENOMEM; - return -1; + goto cleanup; } parse_acl_file(conf_file, acl_list); @@ -197,15 +194,28 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) parse_acl_file(arg, acl_list); } else { fprintf(stderr, "Unknown command `%s'\n", cmd); - fclose(f); errno = EINVAL; - return -1; + goto cleanup; } } fclose(f); return 0; + +cleanup: + + fclose(f); + + if (include_list) { + for (i = 0; i < include_count; i++) { + if (include_list[i]) + free(include_list[i]); + } + free(include_list); + } + + return -1; } static bool has_vnet_hdr(int fd)