[Mono-bugs] [Bug 375222] New: DllImported function with string return crashes Mono

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Mar 29 17:58:08 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=375222


           Summary: DllImported function with string return crashes Mono
           Product: Mono: Runtime
           Version: SVN
          Platform: x86-64
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: interop
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: jan.oravec at 6com.sk
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


Let's have simple C library:

char* goo ()
{
  return "hello world";
}

And simple C# code that use this library:

using System;
using System.Runtime.InteropServices;

class M
{
//  [ DllImport ("/tmp/test.so") ]
//  static extern IntPtr goo ();

  [ DllImport ("/tmp/test.so") ]
  [ return : MarshalAs (UnmanagedType.LPStr) ]
  static extern string goo ();

  public static void Main ()
  {
//    Console.WriteLine (Marshal.PtrToStringAnsi (goo ()));
    Console.WriteLine (goo ());
  }
}

This code crash Mono, while commented out version works as expected.
Interesting part of crash reveals, that probably Mono is trying to free that
static string C code, which is wrong for returned string:

Stacktrace:

  at (wrapper managed-to-native) System.Object.__icall_wrapper_g_free (intptr)
<0x00045>
  at (wrapper managed-to-native) System.Object.__icall_wrapper_g_free (intptr)
<0xffffffff>
  at (wrapper managed-to-native) M.goo () <0xffffffff>
  at M.Main () <0x00008>
  at (wrapper runtime-invoke) System.Object.runtime_invoke_void
(object,intptr,intptr,intptr) <0xffffffff>


Also, changing C code to "return strdup ("hello world");" eliminates crash.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list