Bug 41061 - Marshal Release crash application
Summary: Marshal Release crash application
Status: RESOLVED INVALID
Alias: None
Product: Runtime
Classification: Mono
Component: Remoting ()
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-05-12 16:28 UTC by Stanislav
Modified: 2016-05-13 07:14 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Stanislav 2016-05-12 16:28:09 UTC
Greeting Developers!

I'm created simple application using marshal, but it's crashed by using method Marshal.Release(ptr);

P.S.: Unfortunately, I do not understand what the cause of the problem. Thank you for help!

--------------------------------------------------------
Source code:

using System;
using System.Runtime.InteropServices;

namespace MarshalTest
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] tmp = new byte[100];

            for(int i = 0; i < tmp.Length; i++)
            {
                tmp[i] = (byte)i;
            }

            IntPtr ptr = IntPtr.Zero;

            try
            {
                ptr = Marshal.AllocHGlobal(tmp.Length);
                Marshal.Copy(tmp, 0, ptr, tmp.Length);  
            }
            finally
            {

                if (ptr != IntPtr.Zero)
                    Marshal.Release(ptr);
            }
        }
    }
}

--------------------------------------------------------
Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal.ReleaseInternal (intptr) <0xffffffff>
  at System.Runtime.InteropServices.Marshal.Release (intptr) <0x0002e>
  at MarshalTest.Program.Main (string[]) <0x000cc>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

	/usr/bin/cli() [0x49d5fc]
	/usr/bin/cli() [0x4f347e]
	/usr/bin/cli() [0x42498d]
	/lib/x86_64-linux-gnu/libpthread.so.0(+0x10340) [0x7fd9bdebd340]
	/usr/bin/cli() [0x527f38]
	[0x402363c2]

Debug info from gdb:

[New LWP 8153]
[New LWP 8152]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007fd9bdebcee9 in __libc_waitpid (pid=8154, stat_loc=0x7fd9be9ef29c, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40
40	../sysdeps/unix/sysv/linux/waitpid.c: No such file or directory.
  Id   Target Id         Frame 
  3    Thread 0x7fd9bcbff700 (LWP 8152) "cli" pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
  2    Thread 0x7fd9bd2d4700 (LWP 8153) "Finalizer" sem_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S:85
* 1    Thread 0x7fd9be9e17c0 (LWP 8150) "cli" 0x00007fd9bdebcee9 in __libc_waitpid (pid=8154, stat_loc=0x7fd9be9ef29c, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40

Thread 3 (Thread 0x7fd9bcbff700 (LWP 8152)):
#0  pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1  0x00000000005f9aec in ?? ()
#2  0x00007fd9bdeb5182 in start_thread (arg=0x7fd9bcbff700) at pthread_create.c:312
#3  0x00007fd9bdbe247d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

Thread 2 (Thread 0x7fd9bd2d4700 (LWP 8153)):
#0  sem_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S:85
#1  0x000000000061de28 in mono_sem_wait ()
#2  0x00000000005a2076 in ?? ()
#3  0x00000000005843d3 in ?? ()
#4  0x0000000000624666 in ?? ()
#5  0x00007fd9bdeb5182 in start_thread (arg=0x7fd9bd2d4700) at pthread_create.c:312
#6  0x00007fd9bdbe247d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

Thread 1 (Thread 0x7fd9be9e17c0 (LWP 8150)):
#0  0x00007fd9bdebcee9 in __libc_waitpid (pid=8154, stat_loc=0x7fd9be9ef29c, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40
#1  0x000000000049d689 in ?? ()
#2  0x00000000004f347e in ?? ()
#3  0x000000000042498d in ?? ()
#4  <signal handler called>
#5  0x0000000000527f38 in ?? ()
#6  0x00000000402363c2 in ?? ()
#7  0x0000000000efd2e0 in ?? ()
#8  0x00007fffd7d8ad70 in ?? ()
#9  0x0000000000000000 in ?? ()

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================


-----------------------------
d3-linux@d3-linux:~$ mono --version
Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 16 13:19:08 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen
-----------------------------------
Comment 1 Zoltan Varga 2016-05-13 04:39:55 UTC
Marshal.Release () is used to release COM stuff, you want Marshal.FreeHGlobal ().
Comment 2 Stanislav 2016-05-13 07:14:38 UTC
Thank you for your help, application it's working good!