From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 91CAF8009A for ; Sat, 3 Dec 2016 14:20:30 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=rich@annexia.org; spf=Pass smtp.mailfrom=rich@annexia.org; spf=Pass smtp.helo=postmaster@annexia.org Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of rich@annexia.org) identity=pra; client-ip=80.68.91.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of rich@annexia.org designates 80.68.91.176 as permitted sender) identity=mailfrom; client-ip=80.68.91.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@annexia.org designates 80.68.91.176 as permitted sender) identity=helo; client-ip=80.68.91.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="postmaster@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" IronPort-PHdr: =?us-ascii?q?9a23=3AZLaZzRUiLKzne8kv1wSpZs56bxjV8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYZhWOt8tkgFKBZ4jH8fUM07OQ6PG7HzBdqsza+DBaKdoXCE9D0Z?= =?us-ascii?q?1X1yUbQ+e7SmTDZMbwaCI7GMkQHHRExFqcdXZvJcDlelfJqWez5zNBUj/2NA5y?= =?us-ascii?q?O/inUtWK15f//6mI9pbSewRFgiamKfM3dU3u7FaZis5DgI5nI6Asxx+BpnpUaf?= =?us-ascii?q?5R2WMgcVOXngru/MCs/LZs9i1Rv7Qq8MsWAovgeKFtB4ZZBzQvKWx924vO81Hh?= =?us-ascii?q?Sg2C/TFUBn8XmRpgCg7D4QH7V9H2qCSs5bk14zWTIcCjFeN8Yj+l9ao+DUaw0C?= =?us-ascii?q?o=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BuAQC4xUJY/7BbRFBdGgEBAQECAQEBA?= =?us-ascii?q?QgBAQEBFgEBAQMBAQEJAQEBgw0BAQEBAR9agQaNR5ViAQEDAQaBHZAyhEuCCCu?= =?us-ascii?q?FdwKCHT8UAQEBAQEBAQEBAQFhKIIzBAEVAQSCFwEFOj8QCxgJExIPBSghLohYC?= =?us-ascii?q?q9xiz8BAQEBBgEBAQEBHQWFdECEZYd5gjAFmmYBhkqKP5BKSY05hA0fN4EZI4U?= =?us-ascii?q?yPjSIMYFPAQEB?= X-IPAS-Result: =?us-ascii?q?A0BuAQC4xUJY/7BbRFBdGgEBAQECAQEBAQgBAQEBFgEBAQM?= =?us-ascii?q?BAQEJAQEBgw0BAQEBAR9agQaNR5ViAQEDAQaBHZAyhEuCCCuFdwKCHT8UAQEBA?= =?us-ascii?q?QEBAQEBAQFhKIIzBAEVAQSCFwEFOj8QCxgJExIPBSghLohYCq9xiz8BAQEBBgE?= =?us-ascii?q?BAQEBHQWFdECEZYd5gjAFmmYBhkqKP5BKSY05hA0fN4EZI4UyPjSIMYFPAQEB?= X-IronPort-AV: E=Sophos;i="5.33,735,1477954800"; d="scan'208";a="247928817" Received: from annexia.org ([80.68.91.176]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 03 Dec 2016 14:20:29 +0100 Received: from rich by annexia.org with local (Exim 4.84_2) (envelope-from ) id 1cDAEu-0007Kq-O0; Sat, 03 Dec 2016 13:20:28 +0000 Date: Sat, 3 Dec 2016 13:20:28 +0000 From: "Richard W.M. Jones" To: immanuel litzroth Cc: OCaML List Mailing Message-ID: <20161203132028.GA28111@annexia.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [Caml-list] Raising invalid_argument with a constructed string. On Mon, Nov 28, 2016 at 03:39:05PM +0100, immanuel litzroth wrote: > caml_invalid_argument(str) is no return and does not free it's > argument. > So calling it with a string constructed dynamically will mean it'll never > get freed. > I could construct an ocaml string and pass that to caml_raise_with_arg, > but I don't seem to be able to get to the caml_exn_Invalid_argument from > c. Am I missing something? We have the same problem in libguestfs in a few places. The solution is to use an allocation on the C stack, either a fixed size buffer or [although we don't currently use this] a variable sized one using alloca. The string is freed when the stack is unwound. Examples: https://github.com/libguestfs/libguestfs/blob/master/builder/yajl-c.c#L108-L114 https://github.com/libguestfs/libguestfs/blob/master/v2v/domainxml-c.c#L120 Be nice to have a "freeing" version of caml_raise* I suppose. Rich.