Odd segmentation fault on Ubuntu only

Anyone as a clue why my program returns a segmentation fault on Ubuntu but not on Gentoo? I dumped the core and check the output through gdb.

The whole program run fine all the way down and does what its suposed to do up till where its suposed to exit then it crash to segmentation fault instead of exiting... but only on Ubuntu 9.10 not Gentoo which are the 2 distros i tested so far?!?!?!

Core was generated by `./test'.
Program terminated with signal 11, Segmentation fault.
#0  0xb77987b4 in *__GI_getenv (name=0xb788af30 "LIBC_FATAL_STDERR_") at getenv.c:84
84      getenv.c: No such file or directory.
        in getenv.c

Code that crashes deep inside glibc like that usually means you've corrupted your heap or stack with buffer overflows, pointer errors, invalid free() calls or use of already-freed memory, etc, etc. It's quite possible to do this without crashing your program since there's decent odds minor corruption will only hit data or empty memory, not stack frames or heap metadata; but as you've seen, such behavior is extremely system, library, and compiler-dependent. UNIX tries to be as intolerant of these errors as possible, by design; Windows lets you get away with murder by comparison(I once was accidentally freeing the same pointer, 60 times per second, for several minutes, before anything went wrong).

So you need to track down where exactly you're overrunning your buffers or corrupting your heap. Tools like valgrind may help. You could also post your code to let us take a look if its small enough.

Are the versions of the gcc compiler and libraries the same on both platforms? Are both platforms using the same programming model i.e. 32 bits or 64 bits?

From my experience, it usually means that your program has a bug, and that you were lucky enough on Gentoo that the bug doesn't appear. Chances are tiny that it is actually a ubuntu problem.

Did you tried to run your program under valgrind?

HTH,
Lo�c.

On Ubuntu try this before compiling:

echo 0 > /proc/sys/kernel/randomize_va_space

then, use this option for gcc:

gcc <source_code.c> -fno-stack-protector -o test