Yes, I've used that solution too, keeping a static fixed string around, it's just not very nice and will break if it's ever multithreaded. Immanuel On Sat, Dec 3, 2016 at 2:20 PM, Richard W.M. Jones wrote: > 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. >