From: Ian Jackson Subject: Re: [PATCH] libxl: initialize domid to 0 in libxl__create_stubdom Date: Fri, 17 Jun 2011 18:46:46 +0100 Message-ID: <19963.37638.19033.472036@mariner.uk.xensource.com> References: <1307595829.8990.9.camel@limbo> <1307606121.775.761.camel@zakaz.uk.xensource.com> <1307608287.31235.17.camel@limbo> <1307615031.775.810.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1307615031.775.810.camel@zakaz.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Campbell Cc: "xen-devel@lists.xensource.com" , Stefano Stabellini , Wei Liu List-Id: xen-devel@lists.xenproject.org Ian Campbell writes ("[Xen-devel] Re: [PATCH] libxl: initialize domid to 0 in libxl__create_stubdom"): > Yeah, me too, that line could just be hoisted up to the first thing the > function does with no loss of safety AFAICT. The question is really what the error handling pattern is expected to be in the caller. Our usual error handling pattern (which I think is a good one) is something like: char *something = NULL; uint32_t domid = -1; ... something = allocate(); if (!something) goto error_exit; ... ret = libxl__domain_make(&domid); if (ret) goto error_exit; ... return successfully somehow; error_exit: free(something); if (libxl_domid_valid_guest(domid)) libxl_domain_destroy(domid); If we expect callers of libxl__domain_make to do this with the domid then there is no benefit to doing the initialisation in libxl__domain_make; indeed doing so would just mask failure-to-initialise bugs in the caller - bugs which the compiler can't spot. Defining the interface to libxl__domain_make to _not_ initialise the value means that the bug of writing uint32_t domid; rather than uint32_t domid = -1; can be detected by valgrind at least and also standds a chance of failing the assertion. Ian.