473,230 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

infinite loop in malloc?

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#

Jun 15 '06 #1
1 1703
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.


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/is...k/default.aspx

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


Jun 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
5
by: mailpitches | last post by:
Hello, Is there any way to kill a Javascript infinite loop in Safari without force-quitting the browser? MP
7
by: vjay | last post by:
I want to just create a linklist.The program below goes into an endless loop.The srange behaviour is that i can exit from the program if i create only two nodes.After two goes into infinite loop. ...
10
by: Steven Woody | last post by:
i have a program which always run dead after one or two days, i think somewhere a piece of the code is suspicious of involving into a infinite loop. but for some reason, it is very hard to debug....
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.