From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH for-4.6 12/13] tools/ocaml: call libxl_dominfo_{init, dispose} in stub Date: Thu, 23 Jul 2015 09:32:44 +0100 Message-ID: <55B0A6AC.2000903@citrix.com> References: <1437638354-14216-1-git-send-email-wei.liu2@citrix.com> <1437638354-14216-13-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZIBvo-00010j-Lm for xen-devel@lists.xenproject.org; Thu, 23 Jul 2015 08:32:44 +0000 In-Reply-To: <1437638354-14216-13-git-send-email-wei.liu2@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: Wei Liu , Xen-devel Cc: Ian Jackson , Ian Campbell , David Scott List-Id: xen-devel@lists.xenproject.org On 23/07/2015 08:59, Wei Liu wrote: > Signed-off-by: Wei Liu > --- > Cc: David Scott > > As far as I can tell, all Val_$foo function does deep-copy, so we can > safely call dispose in said function. Sadly this is insufficient. failwith_xl() longjump()s back into the ocaml runtime, which ends up leaking any allocations made for dominfo. This is a systemic problem with the Ocaml bindings and I have a proposed solution but it involves rewriting quite a lot of this code and is definitely not 4.6 material. ~Andrew > --- > tools/ocaml/libs/xl/xenlight_stubs.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xenlight_stubs.c > index 4133527..7b8d6db 100644 > --- a/tools/ocaml/libs/xl/xenlight_stubs.c > +++ b/tools/ocaml/libs/xl/xenlight_stubs.c > @@ -979,14 +979,18 @@ value stub_xl_dominfo_get(value ctx, value domid) > int ret; > uint32_t c_domid = Int_val(domid); > > + libxl_dominfo_init(&c_dominfo); > + > caml_enter_blocking_section(); > ret = libxl_domain_info(CTX, &c_dominfo, c_domid); > caml_leave_blocking_section(); > > - if (ret != 0) > + if (ret != 0) { > failwith_xl(ERROR_FAIL, "domain_info"); > + libxl_dominfo_dispose(&c_dominfo); > + } > dominfo = Val_dominfo(&c_dominfo); > - > + libxl_dominfo_dispose(&c_dominfo); > CAMLreturn(dominfo); > } >