473,394 Members | 1,746 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,394 software developers and data experts.

NULL pointer returned in calloc

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
Dec 4 '06 #1
3 2057
Alexander Behnke wrote:
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.
Dec 4 '06 #2
Jacek Dziedzic wrote:
>
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
Dec 4 '06 #3
Alexander Behnke wrote:
Jacek Dziedzic wrote:
>>
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
Dec 4 '06 #4

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

Similar topics

26
by: Christopher Benson-Manica | last post by:
I have, in a certain unnamed header file, the following: #define PIPE_WAIT 0x00000000 #define PIPE_NOWAIT 0x00000001 and a function that the compiler believes...
29
by: Jason Curl | last post by:
I've been reading this newsgroup for some time and now I am thoroughly confused over what NULL means. I've read a NULL pointer is zero (or zero typecast as a void pointer), others say it's...
99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
69
by: fieldfallow | last post by:
Hello all, Before stating my question, I should mention that I'm fairly new to C. Now, I attempted a small demo that prints out the values of C's numeric types, both uninitialised and after...
44
by: sam_cit | last post by:
Hi Everyone, I tried the following program unit in Microsoft Visual c++ 6.0 and the program caused unexpected behavior, #include <stdio.h> #include <string.h> int main() {
46
by: lovecreatesbea... | last post by:
Do you prefer malloc or calloc? p = malloc(size); Which of the following two is right to get same storage same as the above call? p = calloc(1, size); p = calloc(size, 1);
2
by: andrey.vul | last post by:
code: #include <iostream> #include <vector> #include <stdexcept> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring>
9
by: Francois Grieu | last post by:
When running the following code under MinGW, I get realloc(p,0) returned NULL Is that a non-conformance? TIA, Francois Grieu #include <stdio.h> #include <stdlib.h>
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.