Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2006

Tip: Looking for answers? Try searching our database.

infinite loop in malloc?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 15 Jun 2006 21:14 GMT
Hi All,

I'm an experienced C# developer that has very little experience with
C++.  Unfortunately, it fell to me to wrap some unmanaged c++ (itself
ported from ADA) to provide managed types that can be consumed by other
C# developers on my team.  So!  I'm trying to use Managed Extensions
(.NET Framework v1.1) to achieve my goal.

I have a C++.NET DLL that compiles and links.  In it, a managed type
contains (as a private member) the unmanaged type that I am wrapping.
When, in the managed type's constructor, I attempt to new up the
unmanaged type, I crash with a stack overflow exception.

So I set some options that would allow me to debug down into MS code.
What I found was an infinite loop, which explains the stack overflow.
The problem is that I don't know what is causing the infinite loop.  I
see [I think] that the code is trying and failing to lock the heap.
And here's where my lack of experience in C++ hurts me.  I have no idea
why it would fail, and definitely no idea why it would infinitely
re-attempt until the stack overflows.

This type of error makes me think that I'm doing something silly due to
my lack of experience.  The stack trace is shown below.  Does anyone
have any idea what I may be doing wrong?

Thanks!
John

    DBaseWrapper.dll!_lock(int locknum=4)  Line 304    C
    DBaseWrapper.dll!_nh_malloc_dbg(unsigned int nSize=24, int nhFlag=0,
int nBlockUse=2, const char * szFileName=0x1007c4e4, int nLine=251)
Line 254 + 0x7    C
    DBaseWrapper.dll!_malloc_dbg(unsigned int nSize=24, int nBlockUse=2,
const char * szFileName=0x1007c4e4, int nLine=251)  Line 176 + 0x1b    C
    DBaseWrapper.dll!_mtinitlocknum(int locknum=4)  Line 251 + 0x13    C
    DBaseWrapper.dll!_lock(int locknum=4)  Line 311 + 0x9    C
    DBaseWrapper.dll!_nh_malloc_dbg(unsigned int nSize=24, int nhFlag=0,
int nBlockUse=2, const char * szFileName=0x1007c4e4, int nLine=251)
Line 254 + 0x7    C
    DBaseWrapper.dll!_malloc_dbg(unsigned int nSize=24, int nBlockUse=2,
const char * szFileName=0x1007c4e4, int nLine=251)  Line 176 + 0x1b    C
    DBaseWrapper.dll!_mtinitlocknum(int locknum=4)  Line 251 + 0x13    C
    DBaseWrapper.dll!_lock(int locknum=4)  Line 311 + 0x9    C
    DBaseWrapper.dll!_nh_malloc_dbg(unsigned int nSize=516, int nhFlag=0,
int nBlockUse=1, const char * szFileName=0x00000000, int nLine=0)  Line
254 + 0x7    C
    DBaseWrapper.dll!malloc(unsigned int nSize=516)  Line 139 + 0x15    C
    DBaseWrapper.dll!operator new(unsigned int size=516)  Line 12 +
0x9    C++
    Adapter.exe!Adapter.UnmanagedDB.UnmanagedDB() Line 20 + 0x14 bytes    C#
    Adapter.exe!Adapter.UnmanagedDB.Main() Line 35 + 0x14 bytes    C#
Oleg Starodumov - 16 Jun 2006 10:08 GMT
> I have a C++.NET DLL that compiles and links.  In it, a managed type
> contains (as a private member) the unmanaged type that I am wrapping.
[quoted text clipped - 8 lines]
> why it would fail, and definitely no idea why it would infinitely
> re-attempt until the stack overflows.

It looks like CRT library is not initialized.

Usually your DLL should provide initialization and cleanup functions for CRT,
and the client should call them. You can find the details in these articles:
http://support.microsoft.com/?id=814472
http://msdn.microsoft.com/msdnmag/issues/05/02/CATWork/default.aspx

Regards,
Oleg
[VC++ MVP http://www.debuginfo.com/]

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.