*BSDThis forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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.
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?
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.