[Gambas-user] Segfault when freeing pointer used for Extern

Benoît Minisini gambas at ...1...
Wed Nov 6 01:07:29 CET 2013


Le 06/11/2013 00:58, Bruce a écrit :
> Dear experts,
>
> Can anyone see what I'm doing wrong here.  Source archive is attached,
> but here is the entire code:
>
> ----------------------------------------------------------------------
> ' Gambas module file
>
> ' void uuid_generate(uuid_t out);
> Extern UUID_Gen(op As Pointer) As Pointer In "libuuid:1" Exec
> "uuid_generate"
>
> ' void uuid_unparse(uuid_t uu, char *out)
> Extern UUID_ToStr(ip As Pointer, op As Pointer) As Pointer In
> "libuuid:1" Exec "uuid_unparse"
>
> Public Sub Main()
>
>    Dim OP As Pointer    ' ptr to the uuid returned by uuid_generate
>    Dim SP As Pointer    ' ptr to the string returned by uuid_unparse
>
>    Dim sOP As String    ' our result (UUID as a string)
>    Dim rtn As Integer   ' int rtn code from extern funcs
>    Dim sArch As String  ' system architecture (selects pointer length)
>
>    sArch = System.Architecture
>    Error "Arch=" & sArch
>
>    OP = Alloc(IIf(sArch = "x86", 4, 8))
>    SP = Alloc(IIf(sArch = "x86", 4, 8))
>
>    rtn = UUID_Gen(OP)
>    Error "UUID_Gen=" & rtn
>
>    rtn = UUID_ToStr(OP, SP)
>    sOP = String@(SP)
>    Error Subst("UUID_ToStr=&1\tUUID=&2", rtn, sOP)
>    Error
>
>    Free(OP)
>    Free(SP)
>
> End         '<- the problem happens here
> ----------------------------------------------------------------------
>
> I get variously a SegFault(11) or an Aborted(6) here. The Segfault shows
> nothing, but the Abort produces an invalid pointer dump like the
> following:
>

What is the exact definition of 'uuid_t' ?

Also, you can use valgrind to know when exactly the faulty memory access 
occurs. This will give better clues.

Regards,


-- 
Benoît Minisini




More information about the User mailing list