Connecting Tech Pros Worldwide Forums | Help | Site Map

NULL pointer returned in calloc

Alexander Behnke
Guest
 
Posts: n/a
#1: Dec 4 '06
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::Exce ption::Exception(int
line=32, char * function=0x00483160, char * file=0x004831a0) Line 23 +
0x10 C++
FlowPRESS.exe!FlowPRESS::Support::Exceptions::Allo cationFailedException::AllocationFailedException(i nt
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::in itRS(FlowPRESS::Simulation
* sim=0x0012fdc4) Line 1671 + 0x53 C++
FlowPRESS.exe!FlowPRESS::Module::Triangulation::in itialize(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

Jacek Dziedzic
Guest
 
Posts: n/a
#2: Dec 4 '06

re: NULL pointer returned in calloc


Alexander Behnke wrote:
Quote:
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::Exce ption::Exception(int
line=32, char * function=0x00483160, char * file=0x004831a0) Line 23 +
0x10 C++
FlowPRESS.exe!FlowPRESS::Support::Exceptions::Allo cationFailedException::AllocationFailedException(i nt
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::in itRS(FlowPRESS::Simulation
* sim=0x0012fdc4) Line 1671 + 0x53 C++
FlowPRESS.exe!FlowPRESS::Module::Triangulation::in itialize(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.
Alexander Behnke
Guest
 
Posts: n/a
#3: Dec 4 '06

re: NULL pointer returned in calloc


Jacek Dziedzic wrote:
Quote:
>
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
Alexander Behnke
Guest
 
Posts: n/a
#4: Dec 4 '06

re: NULL pointer returned in calloc


Alexander Behnke wrote:
Quote:
Jacek Dziedzic wrote:
Quote:
>>
> 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
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
Closed Thread