From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vincent Hanquez Subject: [PATCH 4/5] use new gc functions to deep copy structure and only free once the gc. Date: Tue, 10 Aug 2010 12:46:52 +0100 Message-ID: <1281440813-22610-5-git-send-email-vincent.hanquez@eu.citrix.com> References: <1281440813-22610-1-git-send-email-vincent.hanquez@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.7.1" Return-path: In-Reply-To: <1281440813-22610-1-git-send-email-vincent.hanquez@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel Cc: Vincent Hanquez List-Id: xen-devel@lists.xenproject.org --------------1.7.1 Content-Type: text/plain; charset="UTF-8"; format=fixed Content-Transfer-Encoding: quoted-printable Signed-off-by: Vincent Hanquez --- tools/ocaml/libs/xl/xl_stubs.c | 25 +++++++++++++++++++++---- 1 files changed, 21 insertions(+), 4 deletions(-) --------------1.7.1 Content-Type: text/x-patch; name="0004-use-new-gc-functions-to-deep-copy-structure-and-only.patch" Content-Disposition: attachment; filename="0004-use-new-gc-functions-to-deep-copy-structure-and-only.patch" Content-Transfer-Encoding: quoted-printable diff --git a/tools/ocaml/libs/xl/xl_stubs.c b/tools/ocaml/libs/xl/xl_stub= s.c index 7ba9272..8134e8e 100644 --- a/tools/ocaml/libs/xl/xl_stubs.c +++ b/tools/ocaml/libs/xl/xl_stubs.c @@ -63,18 +63,38 @@ void log_destroy(struct xentoollog_logger *logger) failwith_xl("cannot init context", &lg); =20 #define FREE_CTX() \ + gc_free(&gc); \ libxl_ctx_free(&ctx) =20 static void * gc_calloc(caml_gc *gc, size_t nmemb, size_t size) { void *ptr; ptr =3D calloc(nmemb, size); + if (!ptr) + caml_raise_out_of_memory(); + gc->ptrs[gc->offset++] =3D ptr; return ptr; } =20 static char * dup_String_val(caml_gc *gc, value s) { - return String_val(s); + int len; + char *c; + len =3D caml_string_length(s); + c =3D calloc(len + 1, sizeof(char)); + if (!c) + caml_raise_out_of_memory(); + gc->ptrs[gc->offset++] =3D c; + memcpy(c, String_val(s), len); + return c; +} + +static void gc_free(caml_gc *gc) +{ + int i; + for (i =3D 0; i < gc->offset; i++) { + free(gc->ptrs[i]); + } } =20 void failwith_xl(char *fname, struct caml_logger *lg) @@ -349,9 +369,6 @@ value stub_xl_domain_make(value info) =20 FREE_CTX(); =20 - free(c_info.xsdata); - free(c_info.platformdata); - CAMLreturn(Val_int(domid)); } =20 --------------1.7.1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------1.7.1--