From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 48EAFBC88 for ; Sun, 6 Feb 2005 15:01:25 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j16E1ORd024921 for ; Sun, 6 Feb 2005 15:01:25 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA25409 for ; Sun, 6 Feb 2005 15:01:24 +0100 (MET) Received: from pm-mx5.mx.noos.fr (pm-mx5.mgn.net [195.46.220.209]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j16E1Ogf024918 for ; Sun, 6 Feb 2005 15:01:24 +0100 Received: from [192.168.0.2] (m101.net81-66-34.noos.fr [81.66.34.101]) by pm-mx5.mx.noos.fr (Postfix) with ESMTP id 15A2E272D8 for ; Sun, 6 Feb 2005 15:01:23 +0100 (MET) Message-ID: <42062429.4050404@noos.fr> Date: Sun, 06 Feb 2005 15:05:29 +0100 From: julius User-Agent: Mozilla Thunderbird 0.8 (X11/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] Segfault using malloc within stubs Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 42062334.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42062334.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 segfault:01 malloc:01 stubs:01 pointer:01 malloc:01 pointer:01 segfault:01 wrote:01 wrote:01 stubs:01 camlprim:01 foo:01 camlparam:01 char:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: Actually, this is just un exemple that illustrates the real function I used. We can add some use of the test pointer and result value but it changes nothing: in this function you can't do anything that someway malloc the test pointer. As you say it's very weird and much disapointing :) Julius PS: In my implementation, test is given to a function that use it to stock its result (after malloc it), and result is a caml value pointing to some calculus result. The end is same: segfault... Remi Vanicat wrote: > On Sun, 06 Feb 2005 08:38:06 +0100, julius wrote: > > >> Hello, >> >> I have this strange problem with my stubs, I wrote this function but it >> leads to a segfault: >> >> CAMLprim value foo(value v) >> { >> CAMLparam1(v); >> CAML(result); >> char** test; >> >> test=(char**)malloc(4*sizeof(char*)); >> CAMLreturn(result); >> } >> >> After much tests, it seems that malloc is not allowed when using Caml >> data types or when trying to register data to the ocaml garbage >> collector... But I don't understand why as C heap and OCaml heap are >> distinct :-/ >> > > > It seem weird. First of all, mallocs are explicitly allowed in the > doc. So the problem must be somewhere else. I see that in this code, > the test pointer is never used, but throw away, and this could lead to > a memory leak. Also the result variable is never set, so this is > probably the problem. Try to add a result=Val_unit; somewhere in your > code to see if the problem goes away. I forget : I don't know what > CAML(result) mean. Did you want to use CAML_local1(result) ? may be > this is the problem. > > > >