LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-17-2006, 06:19 PM   #31
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled

xinminhua - You said:
Quote:
My reply:
You are right ... But we want to understand it.
Hopefully, based on all this information, you now understand the issues. And why your program might "appear" to work on one platform ... and fail on another ... despite the fact that it's a bug on all platforms.

Hopefully, too, you've found and corrected the problem (my money is definitely on mhcox's suggestion: double-freeing pointers).

Most of all, please take sundialsvcs's suggestions to heart - maybe even formalize them in coding guidelines for your team, and enforce them in team code reviews:
Quote:
I advise the following self-disciplines with respect to dynamically allocated memory.

1. "A pointer's value shall be NULL or it shall point to a valid block of storage." Therefore, the statement immediately following should be p = NULL;.
2. "All dynamically-allocated blocks of storage shall be immediately initialized to a known value, such as zeroes." Either use a storage allocation function that does this, or do it yourself.
3. "Allocate all buffers four to eight bytes larger than they need to be, make sure all those bytes are known-zero, and don't tell anyone they exist when you quote the size of the buffer."
4. "When manipulating strings, always use functions that require you to give the size of the buffer and that will not write beyond that." Remember the trailing-null that some routines stomp past the end of the buffer.
5. "Always check. Don't assume. When something is wrong, fail noisily."
6. "Insert debugging code into your program until you are certain that it is completely debugged. Then, and only then ... leave it in. "
Definitely good advice there!

Finally - please let us know what happens!

Sincerely .. PSM

Last edited by paulsm4; 08-17-2006 at 06:21 PM.
 
Old 08-18-2006, 01:17 AM   #32
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by sundialsvcs
  • "Allocate all buffers four to eight bytes larger than they need to be, make sure all those bytes are known-zero, and don't tell anyone they exist when you quote the size of the buffer."
While I support the other advices, that one may be more dubious, as it basically allows code presenting small overflow bugs to run undetected, including by valgrind, purify or Sun's studio RTC.
 
Old 08-18-2006, 03:43 PM   #33
mhcox
Member
 
Registered: Aug 2005
Location: Albuquerque, NM
Distribution: Fedora
Posts: 30

Rep: Reputation: 15
Quote:
Originally Posted by paulsm4
xinminhua - You said:

Hopefully, based on all this information, you now understand the issues. And why your program might "appear" to work on one platform ... and fail on another ... despite the fact that it's a bug on all platforms.

Hopefully, too, you've found and corrected the problem (my money is definitely on mhcox's suggestion: double-freeing pointers).

Most of all, please take sundialsvcs's suggestions to heart - maybe even formalize them in coding guidelines for your team, and enforce them in team code reviewsefinitely good advice there!

Finally - please let us know what happens!

Sincerely .. PSM
.
.
.
7. Regularly compile your code with memory error detection tools like Purify, valgrind, etc. and run the code through a suite of unit-tests.

Mike
 
  


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
Clear Free Memory lowlifeish Linux - General 3 12-12-2005 12:12 PM
How do I clear the memory cache on my linux server? robgo777 Linux - Software 2 01-09-2005 01:30 AM
Not enough free space on hard drive with 50g of free space??? auoq SUSE / openSUSE 5 10-13-2004 08:21 PM
Formating free space: WinXP pro and RH9 dualboot with free space on 3rd drive Vermicious Linux - General 2 03-22-2004 05:10 AM
Clear out Linux Mandrake disk space? aaronlc Linux - Software 5 02-18-2003 07:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:56 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration