Odd segmentation fault on Ubuntu only


 
Thread Tools Search this Thread
Top Forums Programming Odd segmentation fault on Ubuntu only
# 1  
Old 02-26-2010
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?!?!?!

Code:
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

# 2  
Old 02-26-2010
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.

Last edited by Corona688; 02-26-2010 at 11:36 AM..
# 3  
Old 02-26-2010
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?
# 4  
Old 02-27-2010
Quote:
Originally Posted by Jess83
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?!?!?!
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.
# 5  
Old 02-27-2010
On Ubuntu try this before compiling:
Code:
echo 0 > /proc/sys/kernel/randomize_va_space

then, use this option for gcc:

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


Last edited by Neo; 02-27-2010 at 10:54 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies

2. Programming

Segmentation fault

I keep getting this fault on a lot of the codes I write, I'm not exactly sure why so I'd really appreciate it if someone could explain the idea to me. For example this code #include <stdio.h> main() { unsigned long a=0; unsigned long b=0; int z; { printf("Enter two... (2 Replies)
Discussion started by: sizzler786
2 Replies

3. Solaris

Segmentation fault

Hi Guys, I just installed and booted a zone called testzone. When I logged in remotely and tried changing to root user I get this error: "Segmentation fault" Can someone please help me resolve this? Thanks alot (2 Replies)
Discussion started by: cjashu
2 Replies

4. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

5. Ubuntu

Ubuntu 10.04: Sybase with Perl Segmentation Fault

Hi, Operating System: Ubuntu 10.04 Other Packages Installed: freetds,DBI,DBD-Sybase I am trying to connect to SYBASE using perl programming..But the moment I am executing my perl program it throws a SEGMENTATION FAULT error. I have attached strace output for the same... Thanks for... (1 Reply)
Discussion started by: vnkatara
1 Replies

6. Programming

Segmentation fault in C

i have this code int already_there(char *client_names, char *username) { int i; for(i = 0; i<NUM; i++) { printf("HERE\n"); if (strcmp(client_names, username)==0) return(1); } return(0); } and i get a segmentation fault, whats wrong here? (7 Replies)
Discussion started by: omega666
7 Replies

7. Programming

Segmentation fault.

I'm getting a segmentation fault. I'm new to Linux programming. Thanks so much for all of your input.:eek: #include </usr/include/mysql++/mysql++.h> #include <stdio.h> #include <iostream> #include <sstream> #include <string.h> using namespace std; int outputToImport(const char*... (1 Reply)
Discussion started by: sepoto
1 Replies

8. Programming

segmentation fault

If I do this. Assume struct life { char *nolife; } struct life **life; // malloc initialization & everything if(life->nolife == 0) Would I get error at life->nolife if it is equal to 0. wrong accession? (3 Replies)
Discussion started by: joey
3 Replies

9. UNIX for Dummies Questions & Answers

Segmentation Fault

Hi, While comparing primary key data of two tables thr bteq script I am getting this Error. This script is a shell script. *** Error: The following error was encountered on the output file. Script.sh: 3043492 Segmentation fault(coredump) Please let me know how to get through it. ... (5 Replies)
Discussion started by: monika
5 Replies

10. Programming

Why not a segmentation fault??

Hi, Why I don't receive a segmentation fault in the following sample. int main(void) { char buff; sprintf(buff,"Hello world"); printf("%s\n",buff); } If I define a buffer of 10 elements and I'm trying to put inside it twelve elements, Should I receive a sigsev... (22 Replies)
Discussion started by: lagigliaivan
22 Replies
Login or Register to Ask a Question