Memory Fault

Hello All,

I am porting some C code developed in Windows to QNX. The code works fine in
the Windows environment however in QNX I get a memory fault. I believe I
have pinpointed the error to a free statement, but I could be wrong. Is
there any thing I should know about memory allocations that might be
different from the way memory is allocated, if so, what would be a good
resource to check out.

Thanks in advance,

Elmer Thomas
Computer Engineer
University of California, Riverside
ethomas@cs.ucr.edu

That means you have a bug in your code that was not tickled under Windows
because of the way either the OS or the C libs do memory allocation. :slight_smile:
I can remember a time when I switched from VC++ to Watcom under Windows and
I found 5-10 really nasty bugs because Watcom was much more agressive in it’s
optimization of memory useage. It always made me wonder why VC++ did the
things it did.

chris


Elmer Thomas <ethomas@cs.ucr.edu> wrote:

Hello All,

I am porting some C code developed in Windows to QNX. The code works fine in
the Windows environment however in QNX I get a memory fault. I believe I
have pinpointed the error to a free statement, but I could be wrong. Is
there any thing I should know about memory allocations that might be
different from the way memory is allocated, if so, what would be a good
resource to check out.

Thanks in advance,

Elmer Thomas
Computer Engineer
University of California, Riverside
ethomas@cs.ucr.edu

cdm@qnx.com > “The faster I go, the behinder I get.”

Chris McKillop – Lewis Carroll –
Software Engineer, QSSL
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Thanks Chris,

They do not have any kind of debugger installed on thier machines. How would
you recommend I tackle this problem? Or should I beg for them to install a
debugger?

Thanks,

Elmer

“Chris McKillop” <cdm@qnx.com> wrote in message
news:9h7ts2$jrn$1@nntp.qnx.com

That means you have a bug in your code that was not tickled under Windows
because of the way either the OS or the C libs do memory allocation. > :slight_smile:
I can remember a time when I switched from VC++ to Watcom under Windows
and
I found 5-10 really nasty bugs because Watcom was much more agressive in
it’s
optimization of memory useage. It always made me wonder why VC++ did the
things it did.

chris


Elmer Thomas <> ethomas@cs.ucr.edu> > wrote:

Hello All,

I am porting some C code developed in Windows to QNX. The code works
fine in
the Windows environment however in QNX I get a memory fault. I believe
I
have pinpointed the error to a free statement, but I could be wrong. Is
there any thing I should know about memory allocations that might be
different from the way memory is allocated, if so, what would be a good
resource to check out.

Thanks in advance,

Elmer Thomas
Computer Engineer
University of California, Riverside
ethomas@cs.ucr.edu


\

cdm@qnx.com > “The faster I go, the behinder I get.”
Chris McKillop – Lewis Carroll –
Software Engineer, QSSL

Is this a QNX4 or QNX6 machine? Under QNX6 gdb should be included it you
have the compiler tools. If it is QNX4 I think that the Watcom Debugger
is also part of the toolset.

chris


Elmer Thomas <ethomas@cs.ucr.edu> wrote:

Thanks Chris,

They do not have any kind of debugger installed on thier machines. How would
you recommend I tackle this problem? Or should I beg for them to install a
debugger?

Thanks,

Elmer

“Chris McKillop” <> cdm@qnx.com> > wrote in message
news:9h7ts2$jrn$> 1@nntp.qnx.com> …
That means you have a bug in your code that was not tickled under Windows
because of the way either the OS or the C libs do memory allocation. > :slight_smile:
I can remember a time when I switched from VC++ to Watcom under Windows
and
I found 5-10 really nasty bugs because Watcom was much more agressive in
it’s
optimization of memory useage. It always made me wonder why VC++ did the
things it did.

chris


Elmer Thomas <> ethomas@cs.ucr.edu> > wrote:

Hello All,

I am porting some C code developed in Windows to QNX. The code works
fine in
the Windows environment however in QNX I get a memory fault. I believe
I
have pinpointed the error to a free statement, but I could be wrong. Is
there any thing I should know about memory allocations that might be
different from the way memory is allocated, if so, what would be a good
resource to check out.

Thanks in advance,

Elmer Thomas
Computer Engineer
University of California, Riverside
ethomas@cs.ucr.edu


\

cdm@qnx.com > “The faster I go, the behinder I get.”
Chris McKillop – Lewis Carroll –
Software Engineer, QSSL
\

cdm@qnx.com > “The faster I go, the behinder I get.”

Chris McKillop – Lewis Carroll –
Software Engineer, QSSL
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Also - bugs like this tend to be VERY hard to find with a debugger. If it
is crashing in free() that could mean you have corrupted any number of
data structures. It could very well mean you will have to pour over your
code and find it by hand.

chris


Elmer Thomas <ethomas@cs.ucr.edu> wrote:

Thanks Chris,

They do not have any kind of debugger installed on thier machines. How would
you recommend I tackle this problem? Or should I beg for them to install a
debugger?

Thanks,

Elmer

“Chris McKillop” <> cdm@qnx.com> > wrote in message
news:9h7ts2$jrn$> 1@nntp.qnx.com> …
That means you have a bug in your code that was not tickled under Windows
because of the way either the OS or the C libs do memory allocation. > :slight_smile:
I can remember a time when I switched from VC++ to Watcom under Windows
and
I found 5-10 really nasty bugs because Watcom was much more agressive in
it’s
optimization of memory useage. It always made me wonder why VC++ did the
things it did.

chris


Elmer Thomas <> ethomas@cs.ucr.edu> > wrote:

Hello All,

I am porting some C code developed in Windows to QNX. The code works
fine in
the Windows environment however in QNX I get a memory fault. I believe
I
have pinpointed the error to a free statement, but I could be wrong. Is
there any thing I should know about memory allocations that might be
different from the way memory is allocated, if so, what would be a good
resource to check out.

Thanks in advance,

Elmer Thomas
Computer Engineer
University of California, Riverside
ethomas@cs.ucr.edu


\

cdm@qnx.com > “The faster I go, the behinder I get.”
Chris McKillop – Lewis Carroll –
Software Engineer, QSSL
\

cdm@qnx.com > “The faster I go, the behinder I get.”

Chris McKillop – Lewis Carroll –
Software Engineer, QSSL
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

I am using QNX 4. Upon further thought I think I will have to check my
memory allocations to see if they were all allocated correctly in the first
place. The code sets things to NULL when not allocated correctly but no
output is sent to the screen, I suspect that somewhere something is not
being allocated correctly.

Thanks for your time,

Elmer

“Chris McKillop” <cdm@qnx.com> wrote in message
news:9h7uu9$jrn$3@nntp.qnx.com

Also - bugs like this tend to be VERY hard to find with a debugger. If it
is crashing in free() that could mean you have corrupted any number of
data structures. It could very well mean you will have to pour over your
code and find it by hand.

chris


Elmer Thomas <> ethomas@cs.ucr.edu> > wrote:

Thanks Chris,

They do not have any kind of debugger installed on thier machines. How
would
you recommend I tackle this problem? Or should I beg for them to
install a
debugger?

Thanks,

Elmer

“Chris McKillop” <> cdm@qnx.com> > wrote in message
news:9h7ts2$jrn$> 1@nntp.qnx.com> …
That means you have a bug in your code that was not tickled under
Windows
because of the way either the OS or the C libs do memory allocation. > :slight_smile:
I can remember a time when I switched from VC++ to Watcom under Windows
and
I found 5-10 really nasty bugs because Watcom was much more agressive
in
it’s
optimization of memory useage. It always made me wonder why VC++ did
the
things it did.

chris


Elmer Thomas <> ethomas@cs.ucr.edu> > wrote:

Hello All,

I am porting some C code developed in Windows to QNX. The code works
fine in
the Windows environment however in QNX I get a memory fault. I
believe
I
have pinpointed the error to a free statement, but I could be wrong.
Is
there any thing I should know about memory allocations that might be
different from the way memory is allocated, if so, what would be a
good
resource to check out.

Thanks in advance,

Elmer Thomas
Computer Engineer
University of California, Riverside
ethomas@cs.ucr.edu


\



cdm@qnx.com > “The faster I go, the behinder I get.”
Chris McKillop – Lewis Carroll –
Software Engineer, QSSL




\

cdm@qnx.com > “The faster I go, the behinder I get.”
Chris McKillop – Lewis Carroll –
Software Engineer, QSSL

With Watcom free() will crash if passed NULL

“Elmer Thomas” <ethomas@cs.ucr.edu> wrote in message
news:9h7v5u$q72$1@inn.qnx.com

I am using QNX 4. Upon further thought I think I will have to check my
memory allocations to see if they were all allocated correctly in the
first
place. The code sets things to NULL when not allocated correctly but no
output is sent to the screen, I suspect that somewhere something is not
being allocated correctly.

Thanks for your time,

Elmer

“Chris McKillop” <> cdm@qnx.com> > wrote in message
news:9h7uu9$jrn$> 3@nntp.qnx.com> …

Also - bugs like this tend to be VERY hard to find with a debugger. If
it
is crashing in free() that could mean you have corrupted any number of
data structures. It could very well mean you will have to pour over
your
code and find it by hand.

chris


Elmer Thomas <> ethomas@cs.ucr.edu> > wrote:

Thanks Chris,

They do not have any kind of debugger installed on thier machines. How
would
you recommend I tackle this problem? Or should I beg for them to
install a
debugger?

Thanks,

Elmer

“Chris McKillop” <> cdm@qnx.com> > wrote in message
news:9h7ts2$jrn$> 1@nntp.qnx.com> …
That means you have a bug in your code that was not tickled under
Windows
because of the way either the OS or the C libs do memory allocation.
:slight_smile:
I can remember a time when I switched from VC++ to Watcom under
Windows
and
I found 5-10 really nasty bugs because Watcom was much more agressive
in
it’s
optimization of memory useage. It always made me wonder why VC++ did
the
things it did.

chris


Elmer Thomas <> ethomas@cs.ucr.edu> > wrote:

Hello All,

I am porting some C code developed in Windows to QNX. The code
works
fine in
the Windows environment however in QNX I get a memory fault. I
believe
I
have pinpointed the error to a free statement, but I could be
wrong.
Is
there any thing I should know about memory allocations that might
be
different from the way memory is allocated, if so, what would be a
good
resource to check out.

Thanks in advance,

Elmer Thomas
Computer Engineer
University of California, Riverside
ethomas@cs.ucr.edu


\



cdm@qnx.com > “The faster I go, the behinder I get.”
Chris McKillop – Lewis Carroll –
Software Engineer, QSSL




\



cdm@qnx.com > “The faster I go, the behinder I get.”
Chris McKillop – Lewis Carroll –
Software Engineer, QSSL
\

Thanks,

I will look into that. Also is there a limit in QNX for the heapsize?

“Mario Charest” <mcharest@deletezinformatic.com> wrote in message
news:9h84kp$t41$1@inn.qnx.com

With Watcom free() will crash if passed NULL

“Elmer Thomas” <> ethomas@cs.ucr.edu> > wrote in message
news:9h7v5u$q72$> 1@inn.qnx.com> …
I am using QNX 4. Upon further thought I think I will have to check my
memory allocations to see if they were all allocated correctly in the
first
place. The code sets things to NULL when not allocated correctly but no
output is sent to the screen, I suspect that somewhere something is not
being allocated correctly.

Thanks for your time,

Elmer

“Chris McKillop” <> cdm@qnx.com> > wrote in message
news:9h7uu9$jrn$> 3@nntp.qnx.com> …

Also - bugs like this tend to be VERY hard to find with a debugger.
If
it
is crashing in free() that could mean you have corrupted any number of
data structures. It could very well mean you will have to pour over
your
code and find it by hand.

chris


Elmer Thomas <> ethomas@cs.ucr.edu> > wrote:

Thanks Chris,

They do not have any kind of debugger installed on thier machines.
How
would
you recommend I tackle this problem? Or should I beg for them to
install a
debugger?

Thanks,

Elmer

“Chris McKillop” <> cdm@qnx.com> > wrote in message
news:9h7ts2$jrn$> 1@nntp.qnx.com> …
That means you have a bug in your code that was not tickled under
Windows
because of the way either the OS or the C libs do memory
allocation.
:slight_smile:
I can remember a time when I switched from VC++ to Watcom under
Windows
and
I found 5-10 really nasty bugs because Watcom was much more
agressive
in
it’s
optimization of memory useage. It always made me wonder why VC++
did
the
things it did.

chris


Elmer Thomas <> ethomas@cs.ucr.edu> > wrote:

Hello All,

I am porting some C code developed in Windows to QNX. The code
works
fine in
the Windows environment however in QNX I get a memory fault. I
believe
I
have pinpointed the error to a free statement, but I could be
wrong.
Is
there any thing I should know about memory allocations that might
be
different from the way memory is allocated, if so, what would be
a
good
resource to check out.

Thanks in advance,

Elmer Thomas
Computer Engineer
University of California, Riverside
ethomas@cs.ucr.edu


\




cdm@qnx.com > “The faster I go, the behinder I
get.”
Chris McKillop – Lewis Carroll –
Software Engineer, QSSL





\



cdm@qnx.com > “The faster I go, the behinder I get.”
Chris McKillop – Lewis Carroll –
Software Engineer, QSSL


\

Mario Charest <mcharest@deletezinformatic.com> wrote:

With Watcom free() will crash if passed NULL

Are you sure? What version?

ANSI requires free(NULL) to be a no-op. I have never seen it crash.

\

Wojtek Lerch (wojtek@qnx.com) QNX Software Systems Ltd.

Actually by using the debugger I see my error happens just before the free
when I try to do
a->VDim = 0;
The debugger tells me the value of a->VDIM is NULL. This leads me to believe
there is some kind of memory allocation error. Does anyone know what is the
maximum amount of memory you can allocate?

Thanks,

Elmer

“Wojtek Lerch” <wojtek@qnx.com> wrote in message
news:9h8706$pc6$1@nntp.qnx.com

Mario Charest <> mcharest@deletezinformatic.com> > wrote:

With Watcom free() will crash if passed NULL

Are you sure? What version?

ANSI requires free(NULL) to be a no-op. I have never seen it crash.

\

Wojtek Lerch (> wojtek@qnx.com> ) QNX Software Systems Ltd.

“Wojtek Lerch” <wojtek@qnx.com> wrote in message
news:9h8706$pc6$1@nntp.qnx.com

Mario Charest <> mcharest@deletezinformatic.com> > wrote:

With Watcom free() will crash if passed NULL

Are you sure?

If you knew me better you know I’m never sure :wink:
Every time I reply to a post, I’m doing a leap of faith…

What version?

I was once told a program on quics (don’t remember which one)
needed to be compiled with an alternate malloc lib (libmalloc ?)
because the watcom lib version of free didn’t support NULL.

I just tried it with the lastest watcom and I can’t get it to crash ;-(


ANSI requires free(NULL) to be a no-op. I have never seen it crash.

\

Wojtek Lerch (> wojtek@qnx.com> ) QNX Software Systems Ltd.

Previously, Elmer Thomas wrote in comp.os.qnx:

Actually by using the debugger I see my error happens just before the free
when I try to do
a->VDim = 0;
The debugger tells me the value of a->VDIM is NULL. This leads me to believe
there is some kind of memory allocation error. Does anyone know what is the
maximum amount of memory you can allocate?

The maximum amount of memory that you can allocate is 2^^32 or the amount
left in your system, whichever is less. :slight_smile:.


Mitchell Schoenbrun --------- maschoen@pobox.com

Is it possible you have asked malloc to give zero bytes? This will return NULL,
at least in Watcom. This behavior may be compiler dependent.

Elmer Thomas wrote:

Actually by using the debugger I see my error happens just before the free
when I try to do
a->VDim = 0;
The debugger tells me the value of a->VDIM is NULL. This leads me to believe
there is some kind of memory allocation error. Does anyone know what is the
maximum amount of memory you can allocate?

Thanks,

Elmer

“Wojtek Lerch” <> wojtek@qnx.com> > wrote in message
news:9h8706$pc6$> 1@nntp.qnx.com> …
Mario Charest <> mcharest@deletezinformatic.com> > wrote:

With Watcom free() will crash if passed NULL

Are you sure? What version?

ANSI requires free(NULL) to be a no-op. I have never seen it crash.

\

Wojtek Lerch (> wojtek@qnx.com> ) QNX Software Systems Ltd.

“Mitchell Schoenbrun” <maschoen@pobox.com> wrote in message
news:Voyager.010625150140.239B@schoenbrun.com

The maximum amount of memory that you can allocate is 2^^32 or the amount
left in your system, whichever is less. > :slight_smile:> .

I think technically that’s (2^^32)-1 though I’m guessing that most systems
will run out of physical memory before that.

“Bill Caroselli @ Q-TPS” <BillCaroselli@Q-TPS.com> wrote in message
news:9h8dul$5bu$1@inn.qnx.com

“Mitchell Schoenbrun” <> maschoen@pobox.com> > wrote in message
news:> Voyager.010625150140.239B@schoenbrun.com> …
The maximum amount of memory that you can allocate is 2^^32 or the
amount
left in your system, whichever is less. > :slight_smile:> .

I think technically that’s (2^^32)-1 though I’m guessing that most systems
will run out of physical memory before that.

Technically it is limited by maximum number of pages you can map into your
address space, which is usually considerably less than theoretical limit. It
is dependent on CPU architecture, MMU design, memory map a system is
programmed into and OS used. For example, various 32-bit PowerPC cores have
different MMU types and can use one of 2 modes with different mapping
schemes - PREP (PowerPC REference Platform) and CHRP (Common Hardware
Reference Platform). Then OS takes its toll (also different between OSes)
and you end up with something like 2Gb to 3.5Gb of technical limit instead
of theoretical 2^^32.

Then again, some OSes have ways to address more than ‘theoretical limit’
using one of evil tricks provided by chip manufacturers like Intel as
interim solutions. So there are 32-bit systems out there with 16Gb or RAM.
Another incarnation of ‘extended’ and ‘expanded’ memory, reminds me Freddie
Kruger who will come for you once and again, LOL :wink:

  • Igor

“Chris McKillop” <cdm@qnx.com> wrote in message
news:9h7uu9$jrn$3@nntp.qnx.com

Also - bugs like this tend to be VERY hard to find with a debugger. If it
is crashing in free() that could mean you have corrupted any number of
data structures. It could very well mean you will have to pour over your
code and find it by hand.

Actually, running a good lint might catch the problem, along with hundreds
of other cosmetic quibbles that lint will find with most code. Seems I can
usually find at least one ugly bug when linting a project.

“Mario Charest” <mcharest@deletezinformatic.com> wrote in message
news:9h84kp$t41$1@inn.qnx.com

With Watcom free() will crash if passed NULL

not exactly. according to watcom clib listings it handles free(NULL) calls
in right way at least for version 10.6 with last patches (afair B ?).

from clib3r.lib:

free_:
nfree: push ebx
push ecx
push edx
push esi
push ebp
mov esi,eax
test eax,eax
je near ptr L7
; …
L7: pop ebp
pop esi
pop edx
pop ecx
pop ebx
ret

from clib3s.lib:

free: mov edx,dword ptr +4H[esp]
push edx
call near ptr _nfree
add esp,00000004H
ret

_nfree: push ebx
push esi
push edi
push ebp
mov edi,dword ptr +14H[esp]
test edi,edi
je near ptr L7
; …
L7: pop ebp
pop edi
pop esi
pop ebx
ret

“Elmer Thomas” <> ethomas@cs.ucr.edu> > wrote in message
news:9h7v5u$q72$> 1@inn.qnx.com> …
I am using QNX 4. Upon further thought I think I will have to check my
memory allocations to see if they were all allocated correctly in the
first
place. The code sets things to NULL when not allocated correctly but no
output is sent to the screen, I suspect that somewhere something is not
being allocated correctly.

Thanks for your time,

// wbr