From: Ian Campbell Subject: Re: [PATCH V5 27/32] libxl: libxl-json format and load/store configuration functions Date: Mon, 2 Jun 2014 17:19:46 +0100 Message-ID: <1401725986.8841.17.camel@kazak.uk.xensource.com> References: <1400018054-26038-1-git-send-email-wei.liu2@citrix.com> <1400018054-26038-28-git-send-email-wei.liu2@citrix.com> <1400594636.6946.71.camel@kazak.uk.xensource.com> <20140601184157.GB25584@zion.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20140601184157.GB25584@zion.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Wei Liu Cc: ian.jackson@eu.citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Sun, 2014-06-01 at 19:41 +0100, Wei Liu wrote: > On Tue, May 20, 2014 at 03:03:56PM +0100, Ian Campbell wrote: > > On Tue, 2014-05-13 at 22:54 +0100, Wei Liu wrote: > > > Introduce a new format in libxl userdata store called "libxl-json". This > > > format contains the deserialized version of domain configuration of a > > > domain. > > > > > > Two libxl functions to load and store domain configuration are also > > > introduced. They use the new "libxl-json" format. > > > > Is the intention that application should use these to read/modify/write > > the domain config on changes, as opposed to it being internal > > functionality which libxl should use to keep things up to date? > > > > I think it is a valid usecase that a user of libxl wants to know > libxl's view of a guest's configuration, and I think user is free to > manipulate that view if it wants to. I think the get method is fine. The set is more debatable though. > Xl does this in later patch, when it migrate a domain the name is > modified to "XX--incoming" then changed back to "XX". I think Ian J commented on that too, perhaps for other reasons. Anyway, this should happen in libxl_domain_rename, shouldn't it? > > > + */ > > > + if (data[len-1] != '\0') { > > > + data = libxl__realloc(gc, data, len + 1); > > > + data[len] = '\0'; > > > + } > > > + > > > + rc = libxl_domain_config_from_json(ctx, d_config, (const char *)data); > > > + > > > +out: > > > + free(data); > > > > data might have been libxl__realloc'd above, so isn't it gc'd? > > > > No, it's malloc'ed in libxl_read_file_contents. But then you call libxl__realloc(gc,...). Won't that add the new pointer to the gc (and fail to remove the old one from it because it wasn't there)? Then you free it with free() and then GC_FREE will double free it. Ian.