LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   *BSD (https://www.linuxquestions.org/questions/%2Absd-17/)
-   -   FreeBSD Making my Software stable (https://www.linuxquestions.org/questions/%2Absd-17/freebsd-making-my-software-stable-314346/)

MA_D 04-17-2005 11:14 PM

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.

frob23 04-17-2005 11:57 PM

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.

MA_D 04-18-2005 12:07 AM

I always use -Wall. I don't know what -pedantic does, and I haven't been compiling with it.

MA_D 04-18-2005 12:09 AM

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?

frob23 04-18-2005 09:14 AM

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.


All times are GMT -5. The time now is 09:53 AM.