From patchwork Mon Nov 12 21:38:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 198495 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 261362C0092 for ; Tue, 13 Nov 2012 09:34:06 +1100 (EST) Received: from localhost ([::1]:55127 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TY1iM-0005wb-H7 for incoming@patchwork.ozlabs.org; Mon, 12 Nov 2012 16:38:42 -0500 Received: from eggs.gnu.org ([208.118.235.92]:45905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TY1hg-0004In-Vv for qemu-devel@nongnu.org; Mon, 12 Nov 2012 16:38:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TY1hd-0004gw-SV for qemu-devel@nongnu.org; Mon, 12 Nov 2012 16:38:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46005) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TY1hd-0004fa-KV for qemu-devel@nongnu.org; Mon, 12 Nov 2012 16:37:57 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qACLbtq4026772 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 12 Nov 2012 16:37:56 -0500 Received: from blackpad.lan.raisama.net (vpn1-5-14.gru2.redhat.com [10.97.5.14]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qACLbtpL010514; Mon, 12 Nov 2012 16:37:55 -0500 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id C80B020341D; Mon, 12 Nov 2012 19:39:05 -0200 (BRST) From: Eduardo Habkost To: qemu-devel@nongnu.org, Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 12 Nov 2012 19:38:50 -0200 Message-Id: <1352756342-13716-6-git-send-email-ehabkost@redhat.com> In-Reply-To: <1352756342-13716-1-git-send-email-ehabkost@redhat.com> References: <1352756342-13716-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Don Slutz Subject: [Qemu-devel] [PATCH 05/17] target-i386: cpu_x86_init(): move error handling to end of function 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 Doing error handling on a single place will make it easier to make sure memory is freed, and that error information is properly printed or returned to the caller. Signed-off-by: Eduardo Habkost --- target-i386/cpu.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 73b0fa1..69f1204 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1506,17 +1506,20 @@ X86CPU *cpu_x86_init(const char *cpu_model) env->cpu_model_str = cpu_model; if (cpu_x86_register(cpu, cpu_model) < 0) { - object_delete(OBJECT(cpu)); - return NULL; + goto error; } x86_cpu_realize(OBJECT(cpu), &error); if (error) { - error_free(error); - object_delete(OBJECT(cpu)); - return NULL; + goto error; } return cpu; +error: + object_delete(OBJECT(cpu)); + if (error) { + error_free(error); + } + return NULL; } #if !defined(CONFIG_USER_ONLY)