From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?ISO-8859-1?Q?Roger_Pau_Monn=E9?= Subject: Re: [PATCH 14/29] libxl: don't leak xs_read results in libxl__device_nic_from_xs_be Date: Wed, 30 Oct 2013 09:58:35 +0100 Message-ID: <5270CA3B.6040309@citrix.com> References: <1383119525-26033-1-git-send-email-mattjd@gmail.com> <1383119525-26033-15-git-send-email-mattjd@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1383119525-26033-15-git-send-email-mattjd@gmail.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: Matthew Daley , xen-devel@lists.xen.org Cc: Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org On 30/10/13 08:51, Matthew Daley wrote: > Coverity-ID: 1055866 > Signed-off-by: Matthew Daley > --- > tools/libxl/libxl.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c > index 0b29f32..234f3c1 100644 > --- a/tools/libxl/libxl.c > +++ b/tools/libxl/libxl.c > @@ -2975,9 +2975,10 @@ static void libxl__device_nic_from_xs_be(libxl__gc *gc, > > tmp = xs_read(ctx->xsh, XBT_NULL, > libxl__sprintf(gc, "%s/handle", be_path), &len); > - if ( tmp ) > + if ( tmp ) { > nic->devid = atoi(tmp); > - else > + free(tmp); > + } else > nic->devid = 0; > > /* nic->mtu = */ > @@ -2987,6 +2988,7 @@ static void libxl__device_nic_from_xs_be(libxl__gc *gc, > rc = libxl__parse_mac(tmp, nic->mac); > if (rc) > memset(nic->mac, 0, sizeof(nic->mac)); > + free(tmp); > > nic->ip = xs_read(ctx->xsh, XBT_NULL, > libxl__sprintf(gc, "%s/ip", be_path), &len); I think the proper way of dealing with this is to use libxl__xs_read_checked instead of xs_read, that adds the results to the gc.