fopen causing malloc error - HELP!

T

Tank

ld.so.1: internal: malloc failed

I'm getting the above on a simple fopen() in a production program. I
know that fopen calls malloc, but what would cause this and how do I
fix it? Have I hit some kind of # files open limit or something?

I'm running in Solaris 2.6.

Barry
Perot Systems
 
C

Chris Dollin

Tank said:
ld.so.1: internal: malloc failed

I'm getting the above on a simple fopen() in a production program. I
know that fopen calls malloc, but what would cause this and how do I
fix it? Have I hit some kind of # files open limit or something?

More likely, a bug elsewhere has trashed malloc's bookkeeping. You need
to find that bug and fix it.
 
R

Richard Bos

ld.so.1: internal: malloc failed

I'm getting the above on a simple fopen() in a production program. I
know that fopen calls malloc, but what would cause this and how do I
fix it? Have I hit some kind of # files open limit or something?

Possibly, but one would expect that to give a more legible error
message. It's rather more likely that you have, somehow, played havoc
with the allocation arena earlier on in the program, and what you're
seeing here is merely secondary damage.
Since we know nothing about your program it is impossible to be more
specific, but it would probably be a good idea to check your malloc()
and free() (and related) calls, perhaps with the aid of an allocation
checker.

Richard
 
M

Malcolm

Tank said:
I'm getting the above on a simple fopen() in a production program. I
know that fopen calls malloc, but what would cause this and how do I
fix it? Have I hit some kind of # files open limit or something?
Comment out all your code except the call to fopen(), and see if it still
fails. If it does then there is probably something wrong with the file or
the path to it.

Other posters have suggested that you may have corrupted the malloc()
system. Replace the call to fopen() with a call to malloc(). If the malloc()
fails, then this is almost certainly the problem. Unfortunately if the
malloc() succeeds you haven't proved that the malloc() system is not
corrupt.

Comment in code until the bug reappears. Comment out code again until you
have isolated a small section which seems to cause the bug. This will
probably lead you to the problem.
 
R

Richard Bos

Malcolm said:
Comment out all your code except the call to fopen(), and see if it still
fails.

Erm. Commenting out _all_ code except the fopen() call will leave you
with an uncompilable one-liner...

Richard
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top