|
1. Calloc seg fault...
|
|
Tue May 18, 2004 [1:06 PM]
|
dsarky2001
Email not supplied
member since: Aug 1, 2002
|
Reply
|
|
I'm sure this is something that's fairly straightforward, but I can't think how to approach it.
Using ROM memory management, I've just recently started seeing seg faults starting to come out of the calloc call within add_buf.
Now... memory handling has never been my strong point, but I can't think of something that would suddenly start causing calloc to choke.
Has anybody run into something similar? Does anybody have any suggestions for tracking down the issue?
Thanks,
Dsarky and the One Thousand Monkeys
|
|
|
|
|
2. RE: Calloc seg fault...
|
|
Tue May 18, 2004 [3:05 PM]
|
Genghis
Email not supplied
member since: Mar 24, 2000
|
In Reply To
Reply
|
When you hit the segfault in gdb, check to see what the size and count parameters to calloc() look like, see if they're what you expect them to be. I'm guessing not, that they'll be huge because it's possible that you have some stack-trampling happening earlier that is manifesting itself here. For example: char buf[5];
int count = 10;
int sz = 2;
void *mem;
strcpy( buf, "hello world, what a wonderful day!" );
mem = calloc( sz, count );This is what I'm talking about. buf is too small to contain the entire string being copied into it, so the string overflows into count and sz, causing their values to change to something crazy. Make them crazy enough (e.g. if count * sz > 2 32), and they might just cause calloc() to segfault. g
|
|
|
Keyboard missing. Think F1 to continue.
|
|
3. RE: Calloc seg fault...
|
|
Tue May 18, 2004 [4:20 PM]
|
Samson
Email not supplied
member since: Jul 24, 1999
|
In Reply To
Reply
|
|
This is most likely being caused further back on the chain than calloc. You should check and see what the last mud function is that's called before this happens as that will likely be your culprit.
If gdb is insufficient to help you find it, dig up a copy of Valgrind instead and use it. Valgrind has proven to be a very valuable tool in tracking this sort of thing.
|
|
|
|
|
4. RE: Calloc seg fault...
|
|
Tue May 18, 2004 [8:14 PM]
|
Lodren
Email not supplied
member since: Feb 18, 2004
|
In Reply To
Reply
|
|
Agreed. Every time I've had malloc or calloc crashing on me, it turned out something was overrunning an allocated buffer. Most malloc implementations have some kind of debugging mode (usually you set a shell environment variable called MALLOC_DEBUG, or in your code #define MALLOC_DEBUG to the correct value) that can help. When malloc/calloc/realloc/free is called with debugging enabled, it'll do some checks and let you know if any allocated buffers have been smashed. (it checks for other common allocation errors too) If it finds a problem, it'll report it on STDERR. Of course, keep in mind that errors are not checked for until a malloc/calloc/etc call is made.
I also hear good things about Memprof and similar programs. I'm not sure if it could help in your case or not.
|
|
|
|
|
5. RE: Calloc seg fault...
|
|
Fri Jun 4, 2004 [7:18 AM]
|
dsarky2001
Email not supplied
member since: Aug 1, 2002
|
In Reply To
Reply
|
|
Thanks everyone!
While I haven't had a chance to get back and look at this problem again, you've given me some great leads to work from!
Sorry for the delay in sending thanks, it's been a really rough coupla weeks.
Thanks again,
Dsarky and the One Thousand Monkeys
|
|
|
|
|