Bug 28290 - Marshal.AllocCoTaskMem does not throw OutOfMemoryException on alloc failure
Summary: Marshal.AllocCoTaskMem does not throw OutOfMemoryException on alloc failure
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Interop ()
Version: 3.12.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-03-21 09:42 UTC by Brandon Streiff
Modified: 2015-03-22 03:56 UTC (History)
4 users (show)

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


Attachments
Sample program (with VS2012 project) to demonstrate (3.11 KB, application/x-zip-compressed)
2015-03-21 09:42 UTC, Brandon Streiff
Details


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 FIXED

Description Brandon Streiff 2015-03-21 09:42:44 UTC
Created attachment 10440 [details]
Sample program (with VS2012 project) to demonstrate

The Microsoft .NET runtime throws OutOfMemoryException on allocation failure from Marshal.AllocCoTaskMem, as documented here:
https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.alloccotaskmem%28v=vs.100%29.aspx

The Mono runtime will return a null pointer. This is not expected.

The Mono runtime does appear to throw an OutOfMemoryException if you use Marshal.AllocHGlobal.

When running the attached program using the MS.NET and the Mono runtimes, respectively:

Z:\AllocFailure\bin\Debug>AllocFailure.exe
Got OutOfMemoryException from AllocCoTaskMem(int.MaxValue)
Got OutOfMemoryException from AllocHGlobal(int.MaxValue)

Z:\AllocFailure\bin\Debug>mono AllocFailure.exe
Got null pointer from AllocCoTaskMem(int.MaxValue)
Got OutOfMemoryException from AllocHGlobal(int.MaxValue)




Mono version:

Z:\AllocFailure>mono -V
Mono JIT compiler version 3.12.0 (Visual Studio built mono)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           normal
        SIGSEGV:       normal
        Notification:  Thread + polling
        Architecture:  x86
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen
Comment 1 Zoltan Varga 2015-03-22 03:56:24 UTC
Fixed in mono master 6a74b1952ffc7ba4a5331bf1356c4035769f2480.