LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices

Reply
 
Search this Thread
Old 04-17-2005, 11:14 PM   #1
MA_D
Member
 
Registered: Apr 2005
Location: Iowa
Distribution: Archlinux/RHEL/FreeBSD
Posts: 41

Rep: Reputation: 15
FreeBSD Making my Software stable


I've been coding for a while on a machine running FreeBSD. And I recently started testing and playing with the code on a box running Linux. The first thing I noticed was that my application, that was 100% stable in freebsd, was suddenly segfaulting consistantly on Linux. Now, the main reason I had coded on freebsd is because I'm a Linux lover, and I wanted to force myself to make things slightly more portable by coding it on freebsd and then moving it to linux occasionially. Not that there's hardly any difference since I do entirely ansi C stuff..

Anyway though, does anyone have any ideas why I'm seeing insane stability from an app with a lot of memory errors on bsd where on linux it gets shut down left and right?

Also, just a warning for anyone who was planning to code stuff for BSD, it may lead you to believe you have no memory issues when you may in fact have hundreds.
 
Old 04-17-2005, 11:57 PM   #2
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: Ubuntu, FreeBSD, NetBSD
Posts: 1,449

Rep: Reputation: 47
Are you compiling with -Wall -pedantic on FreeBSD?

Also, there are certain memory related things you can turn on and off in FreeBSD to test how programs use memory (for example, you can have mallac always return zero'ed memory or DEADBEEF a boundary around your memory allocations to make it easy to check if you exceed them.

Exactly... what is causing the problems? I'm betting you didn't use -Wall -pedantic though... it's the easiest way to catch these things.
 
Old 04-18-2005, 12:07 AM   #3
MA_D
Member
 
Registered: Apr 2005
Location: Iowa
Distribution: Archlinux/RHEL/FreeBSD
Posts: 41

Original Poster
Rep: Reputation: 15
I always use -Wall. I don't know what -pedantic does, and I haven't been compiling with it.
 
Old 04-18-2005, 12:09 AM   #4
MA_D
Member
 
Registered: Apr 2005
Location: Iowa
Distribution: Archlinux/RHEL/FreeBSD
Posts: 41

Original Poster
Rep: Reputation: 15
I did manage to fix all the memory errors, but I never even realized I had any issues but leaks until I saw it crash so quickly and often on my linux system.
I'm interested in what you are saying about turning these things on and off? What sort of things?
 
Old 04-18-2005, 09:14 AM   #5
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: Ubuntu, FreeBSD, NetBSD
Posts: 1,449

Rep: Reputation: 47
If you look at malloc.conf(5) and pay special attention to the TUNING section, it should give you a basic idea of some of the things you can do. Basically, you want to look at A, J, R, V, and Z. You can set these with the environment variable MALLOC_OPTIONS. Don't set them all at once but try a mixture of them.

If your program performs differently in ANY way because of these options (specifically J and Z which fill the allocated memory with junk or zero's, respectively) you have a problem which needs to be looked at.

Also, I was wrong about -Wall always catching these errors. I went and did some checking myself last night and realized it only caught the most blatant. And -pedantic is more a portability thing. If your code isn't ANSI compatable, it will spit out warnings.

This isn't really only a problem in BSD, I've seen the exact same thing happen from Linux to BSD. Somewhere in my program, I had forgot to initialize a pointer... in Linux the value turned out to point to a section of memory I could read. As I only intended to read from the pointer this was fine. But when I ran it on BSD the pointer was now pointing at an address I couldn't read from and it was crashing like crazy... that took me hours to sort out.

Actually, I didn't even catch it (even though I was aware of such things). Me and a GSA (graduate student assitent) looked over my code for two hours without finding the problem. Finally the Dr. B walked into the room and heard us talking about it. He wandered over, in his normal relaxed manner, pointed at one line of code and said, "Did you properly initialize this?" Then he wandered off again. It was the exact problem with the code which we could not see. He admitted later (when I was no longer so in awe of him) that he did that a lot, just guessing and most of the time being wrong but when he was right it looked really good.

The moral of the story, though, is that I should have been using a debugger and not just reading it with my eyes.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
freebsd 4.7 howto upgrate stable kernelvn *BSD 0 06-20-2005 10:32 AM
How to upgrade FreeBSD 5.1 to latest stable? IntelSlacker *BSD 1 05-16-2005 06:56 PM
Keeping FreeBSD 4.10-stable (current) vaworx *BSD 20 05-02-2005 10:38 PM
FreeBSD 4.10-STABLE vs. 5.2.1-CURRENT entob *BSD 3 09-01-2004 03:30 PM
Making severn stable next week Baldar Red Hat 3 10-31-2003 11:07 AM


All times are GMT -5. The time now is 02:40 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration