Home Dashboard Directory Help
Search

A heap has been corrupted - SqlCeCommand.Dispose - SQL CE 4 SP1 (4.0.8876.1) by Math


Status: 

Active


1
0
Sign in
to vote
Type: Bug
ID: 869627
Opened: 5/8/2014 9:04:09 AM
Access Restriction: Public
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

We are having an intermittent application crash when using SQL CE 4 SP1 (4.0.8876.1), which happen every 1-2 days.

The crash is: Unhandled exception at 0x0000000077714102 (ntdll.dll) in WERBA8A.tmp.mdmp: 0xC0000374: A heap has been corrupted (parameters: 0x000000007778B4B0).

The error happen when doing a call to SqlCeResultSet.Close() (code sample bellow). The crash occur very infrequently, maybe once in several tens of thousands calls. When the error occur the whole application crashes (windows service).

Multiple queries are executed concurrently.

The stack trace is:

    ntdll.dll!RtlReportCriticalFailure\u001e()
    ntdll.dll!RtlpReportHeapFailure\u001e()
    ntdll.dll!RtlpHeapHandleError\u001e()
    ntdll.dll!RtlpLogHeapFailure\u001e()
    ntdll.dll!RtlpAnalyzeHeapFailure\u001e()
    ntdll.dll!RtlpFreeHeap\u001e()
    ntdll.dll!RtlFreeHeap\u001e()
    kernel32.dll!HeapFree\u001e()
    sqlceqp40.dll!operator delete(void *)
    sqlceqp40.dll!QPCommandEnv::~QPCommandEnv(void)
    sqlceqp40.dll!QPCommandEnv::`vector deleting destructor'(unsigned int)
    sqlceqp40.dll!CommandEnvWrapper::Release(void)
    sqlceqp40.dll!QPCommand::Release(void)
    sqlceme40.dll!ME_SafeRelease(struct IUnknown * *)
    [Managed to Native Transition]    
    System.Data.SqlServerCe.dll!System.Data.SqlServerCe.SqlCeCommand.ReleaseNativeInterfaces()
    System.Data.SqlServerCe.dll!System.Data.SqlServerCe.SqlCeCommand.Dispose(bool disposing)
    System.dll!System.ComponentModel.Component.Dispose()
        [--Call to sqlCeResultSet.Close()--]


NOTE. We have a mini dump and an heap dump if required.

UPDATE 2014-05-15:
The crash does not only occur when calling Dispose() but also when calling ExecuteResultSet. The crash only occur when sharing the same connection between multiple commands and executing command simultaneously.

I added a small project which can replicate the problem. (see attachement). I also updated the "Steps to Reproduce" section and added a workaround.
Details
Sign in to post a comment.
Sign in to post a workaround.
Posted by Math on 5/15/2014 at 10:57 AM
Do not share the same connection between different commands executing simultaneously (use a lock) even if the documentation state that:
SQL Server Compact supports multiple simultaneous connections as well as multiple commands sharing the same connection. This means that it is possible to have multiple instances of SqlCeDataReader on the same connection.
File Name Submitted By Submitted On File Size  
WERBA8A.tmp.zip (restricted) 5/8/2014 -
WER4C4D.tmp.WERInternalMetadata.xml (restricted) 5/8/2014 -
WER4AA6.tmp.appcompat.txt (restricted) 5/8/2014 -
Report.zip (restricted) 5/8/2014 -
Program.cs 5/15/2014 3 KB