NULL pointer returned in calloc

  • Thread starter Alexander Behnke
  • Start date
A

Alexander Behnke

Hello,

I am currently facing a problem with a calloc function call which
returns a NULL pointer while in a debugging environment. If I start the
same executable from the shell (not via the debugger) a valid pointer is
returned.

The call stack looks like this:

FlowPRESS.exe!strcat() Line 169 Asm
FlowPRESS.exe!FlowPRESS::Support::Exceptions::Exception::Exception(int
line=32, char * function=0x00483160, char * file=0x004831a0) Line 23 +
0x10 C++
FlowPRESS.exe!FlowPRESS::Support::Exceptions::AllocationFailedException::AllocationFailedException(int
line=32, char * function=0x00483160, char * file=0x004831a0, char *
name=0x00483220) Line 53 + 0x37 C++
// The function below throws the above exceptions due to a null pointer
// returned by calloc
FlowPRESS.exe!FlowPRESS::Support::Data::Recrodset::initialize(unsigned
int size=3480) Line 32 + 0x40 C++
FlowPRESS.exe!FlowPRESS::Module::Triangulation::initRS(FlowPRESS::Simulation
* sim=0x0012fdc4) Line 1671 + 0x53 C++
FlowPRESS.exe!FlowPRESS::Module::Triangulation::initialize(FlowPRESS::Simulation
* sim=0x0012fdc4) Line 1665 + 0x11 C++
FlowPRESS.exe!FlowPRESS::Simulation::run() Line 46 + 0x45 C++
FlowPRESS.exe!test() Line 39 C++
FlowPRESS.exe!main(int argc=1, char * * argv=0x00321368) Line 52 C++
FlowPRESS.exe!mainCRTStartup() Line 59 + 0x19 C
kernel32.dll!7c816fd7()
ntdll.dll!7c925b4f()

The lines the Null pointer appears in are:
_data = (DATA*):):calloc(sz,sizeof(DATA)));
if(_data==NULL)
throw(AllocationFailedException(
__LINE__,__FUNCTION__,__FILE__,"_data");

As stated before, the code executes without an error if executed from shell.
Apparently all function calls to calloc and related functions fail after
a certain point.

A simple test program which gradually increases the memory usage
executed without problems.

I hope you can help with this particular problem. If not, I appreciate
any input on where I could get a solution.

Alex
 
J

Jacek Dziedzic

Alexander said:
Hello,

I am currently facing a problem with a calloc function call which
returns a NULL pointer while in a debugging environment. If I start the
same executable from the shell (not via the debugger) a valid pointer is
returned.

The call stack looks like this:

FlowPRESS.exe!strcat() Line 169 Asm
FlowPRESS.exe!FlowPRESS::Support::Exceptions::Exception::Exception(int
line=32, char * function=0x00483160, char * file=0x004831a0) Line 23 +
0x10 C++
FlowPRESS.exe!FlowPRESS::Support::Exceptions::AllocationFailedException::AllocationFailedException(int
line=32, char * function=0x00483160, char * file=0x004831a0, char *
name=0x00483220) Line 53 + 0x37 C++
// The function below throws the above exceptions due to a null pointer
// returned by calloc
FlowPRESS.exe!FlowPRESS::Support::Data::Recrodset::initialize(unsigned
int size=3480) Line 32 + 0x40 C++
FlowPRESS.exe!FlowPRESS::Module::Triangulation::initRS(FlowPRESS::Simulation
* sim=0x0012fdc4) Line 1671 + 0x53 C++
FlowPRESS.exe!FlowPRESS::Module::Triangulation::initialize(FlowPRESS::Simulation
* sim=0x0012fdc4) Line 1665 + 0x11 C++
FlowPRESS.exe!FlowPRESS::Simulation::run() Line 46 + 0x45 C++
FlowPRESS.exe!test() Line 39 C++
FlowPRESS.exe!main(int argc=1, char * * argv=0x00321368) Line 52 C++
FlowPRESS.exe!mainCRTStartup() Line 59 + 0x19 C
kernel32.dll!7c816fd7()
ntdll.dll!7c925b4f()

The lines the Null pointer appears in are:
_data = (DATA*):):calloc(sz,sizeof(DATA)));
if(_data==NULL)
throw(AllocationFailedException(
__LINE__,__FUNCTION__,__FILE__,"_data");

As stated before, the code executes without an error if executed from
shell.
Apparently all function calls to calloc and related functions fail after
a certain point.

A simple test program which gradually increases the memory usage
executed without problems.

I hope you can help with this particular problem. If not, I appreciate
any input on where I could get a solution.

Alex

Perhaps you're writing outside a buffer somewhere which
thrashes some internal structures used to track the heap,
i.e. the error is in some unrelated place and only pops up
during calloc?

I would investigate the code that executed after the
last successful call to ?alloc and before the first failure
of ?alloc.

HTH,
- J.
 
A

Alexander Behnke

Jacek said:
Perhaps you're writing outside a buffer somewhere which
thrashes some internal structures used to track the heap,
i.e. the error is in some unrelated place and only pops up
during calloc?

I would investigate the code that executed after the
last successful call to ?alloc and before the first failure
of ?alloc.

HTH,
- J.

Hello Jacek,

I can force the error to appear in the function just prior to the
function call. It seems a call to ?alloc with a value greater than a
certain number (or with a certain amount of heap occupied) fails. Well,
seems I have to get each and every pointer to a memory block tracked.

Alex
 
A

Alexander Behnke

Alexander said:
Hello Jacek,

I can force the error to appear in the function just prior to the
function call. It seems a call to ?alloc with a value greater than a
certain number (or with a certain amount of heap occupied) fails. Well,
seems I have to get each and every pointer to a memory block tracked.

Alex

Hello Jacek,

as an old saying goes: 99% of the errors in a program are introduced
by a stupid guy in front of the screen... - found it (a really, really
dumb error, which can only appear in debugging thanks to heap
information written at the end and at the beginning of each block)

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top