Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6617179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:40:23+00:00 2026-05-25T20:40:23+00:00

I have a heap corruption in my multi-threaded managed program. Doing some tests I

  • 0

I have a heap corruption in my multi-threaded managed program. Doing some tests I found that the corruption happens only when the background threads active in the program (they are switchable). The threads use some 3rd party components.

After examining the code of the threads and 3rd party components (with .NET Reflector) I found that they are all managed, i.e. no “unsafe” or “DllImportAttribute” or “P/Invoke”. It seems that the purely managed code causes a heap corruption, is this possible?

UPDATE

Apart from using Marshal class, is it possible to corrupt the heap with threads not being correctly synchronized? An example would be very appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:40:24+00:00Added an answer on May 25, 2026 at 8:40 pm

    It’s definitely possible to corrupt the heap without any use of unsafe code. The Marshal class is your friend / enemy here

    IntPtr ptr = new IntPtr(50000);  // Random memory
    byte[] b = new byte[100];
    Marshalp.Copy(b, 0, ptr, 100);
    

    This effectively copies 100 consecutive 0’s into the heap at address 50000.

    Another way is with explicit struct layouts

    [StructLayout(LayoutKind.Explicit)]
    struct S1
    {
        [FieldOffset(0)]
        internal string str;
    
        [FieldOffset(0)]
        internal object obj;
    }
    
    S1 s = new S1();
    s.obj = new Program();
    s.str.Trim();  // Hope that works ... :) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a heap of unit tests that need to check XML outputs. I
We have a java program that requires a large amount of heap space -
I have a heap based table in MySQL that I am trying to update
Dup of Some Basic PHP Questions Hello, I have a heap of tinyint fields
I have a whole heap of legacy code that I checked into my SVN
What is the largest heap you have personally used in a managed environment such
I have a c++ program that dies because of out of memory error. Do
I am doing some maintenance on a C++ windows dll library that is required
We have a test case that crashes our big MFC-based app with a heap
When I compile in release mode, I have heap corruption on the deallocation of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.