From: Wei Liu Subject: Re: [PATCH for-4.5] xl: fix two memory leaks Date: Mon, 1 Dec 2014 10:10:06 +0000 Message-ID: <20141201101005.GA19896@zion.uk.xensource.com> References: <1417384485-20874-1-git-send-email-wei.liu2@citrix.com> <1417426487.23604.74.camel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1417426487.23604.74.camel@citrix.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: Ian Campbell Cc: Ian Jackson , Wei Liu , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Mon, Dec 01, 2014 at 09:34:47AM +0000, Ian Campbell wrote: > On Sun, 2014-11-30 at 21:54 +0000, Wei Liu wrote: > > There are two invocations of libxl_basename, which returns a malloc'ed > > string. Those strings should be freed after used. > > > > Signed-off-by: Wei Liu > > Cc: Ian Campbell > > Cc: Ian Jackson > > --- > > tools/libxl/xl_cmdimpl.c | 9 +++++++-- > > 1 file changed, 7 insertions(+), 2 deletions(-) > > > > diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c > > index 9afef3f..716a865 100644 > > --- a/tools/libxl/xl_cmdimpl.c > > +++ b/tools/libxl/xl_cmdimpl.c > > @@ -920,6 +920,7 @@ static void parse_config_data(const char *config_source, > > int pci_permissive = 0; > > int pci_seize = 0; > > int i, e; > > + const char *basename; > > > > libxl_domain_create_info *c_info = &d_config->c_info; > > libxl_domain_build_info *b_info = &d_config->b_info; > > @@ -1116,13 +1117,16 @@ static void parse_config_data(const char *config_source, > > > > switch(b_info->type) { > > case LIBXL_DOMAIN_TYPE_HVM: > > - if (!strcmp(libxl_basename(b_info->kernel), "hvmloader")) { > > + basename = libxl_basename(b_info->kernel); > > + if (!strcmp(basename, "hvmloader")) { > > fprintf(stderr, "WARNING: you seem to be using \"kernel\" " > > "directive to override HVM guest firmware. Ignore " > > "that. Use \"firmware_override\" instead if you " > > "really want a non-default firmware\n"); > > b_info->kernel = NULL; > > } > > + free((void*)basename); > > I think you should un-const the declaration (in both cases) rather than > adding casts. > Is it OK to change the declaration of a public API? Wei. > > + basename = NULL; > > > > xlu_cfg_replace_string (config, "firmware_override", > > &b_info->u.hvm.firmware, 0); > > @@ -7021,7 +7025,7 @@ int main_cpupoolcreate(int argc, char **argv) > > int config_len = 0; > > XLU_Config *config; > > const char *buf; > > - const char *name; > > + const char *name = NULL; > > uint32_t poolid; > > libxl_scheduler sched = 0; > > XLU_ConfigList *cpus; > > @@ -7196,6 +7200,7 @@ out_cfg: > > xlu_cfg_destroy(config); > > out: > > free(config_data); > > + free((void*)name); > > return rc; > > } > > >