From: Wei Liu Subject: Re: [PATCH for-4.5] tools/libxl: Use of init()/dispose() to avoid leaking libxl_dominfo.ssid_label Date: Mon, 5 Jan 2015 14:40:14 +0000 Message-ID: <20150105144014.GK24360@zion.uk.xensource.com> References: <1420467598-2660-1-git-send-email-andrew.cooper3@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: <1420467598-2660-1-git-send-email-andrew.cooper3@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: Andrew Cooper Cc: Wei Liu , Ian Jackson , Ian Campbell , Xen-devel List-Id: xen-devel@lists.xenproject.org On Mon, Jan 05, 2015 at 02:19:58PM +0000, Andrew Cooper wrote: > libxl_dominfo contains a ssid_label pointer which will have memory allocated > for it in libxl_domain_info() if the hypervisor has CONFIG_XSM compiled. > However, the lack of appropriate use of libxl_dominfo_{init,dispose}() will > cause the label string to be leaked, even in success cases. > > This was discovered by XenServers Coverity scanning, and are issues not > identified by upstream Coverity Scan. > > Signed-off-by: Andrew Cooper > CC: Ian Campbell > CC: Ian Jackson Reviewed-by : Wei Liu > CC: Konrad Rzeszutek Wilk > > --- > > Requesting a release-exception as suggested by IanJ. These are memory leaks > which accumulate via the successful completion of libxl library functions (if > XSM is enabled), which will undoubtedly cause issues for the likes of libvirt > and xenopsd-libxl which use libxl in daemon processes. > > As we are very close to the release, I have opted for the more > obviously-correct code rather than the pragmatically better code, particularly > in two locations where libxl_domain_info() is called in a loop, and the > dispose()/init() pair is required to prevent leaking the allocation on each > iteration. > > All of the uses of libxl_domain_info() patched here could better be an > xc_dominfo_getlist() which reduces the quantity of hypercalls made, and the > amount of data transformation done behind the scenes. > --- > tools/libxl/libxl.c | 26 ++++++++++++++++++++++++-- > tools/libxl/libxl_dom.c | 14 ++++++++++---- > 2 files changed, 34 insertions(+), 6 deletions(-) > > diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c > index 50a8928..372dd3b 100644 > --- a/tools/libxl/libxl.c > +++ b/tools/libxl/libxl.c > @@ -364,6 +364,8 @@ int libxl__domain_rename(libxl__gc *gc, uint32_t domid, (This function is really convoluted. :-/)