Opened 17 years ago

Closed 15 years ago

Last modified 15 years ago

#281 closed Defect (fixed)

lib/mfile.C should consider "buf" still exists when realloc()==NULL

Reported by: Joses Owned by: davea
Priority: Undetermined Milestone: Undetermined
Component: Client - Build Version:
Keywords: Cc:

Description

Please consider the attached file as "highlighting" or "suggesting" fixes for existing realloc() functions since the actual code shown is untested.

Just a note: If realloc() finds out it doesn't have enough memory to do what needs to be done it returns the value NULL (but the existing memory buffer still exists).

Reason for suggesting this enhancement is due to experience with plenty of other programs which don't take NULL into account (this becomes a bit of a problem with computers that have limited RAM computers and limited or (worse) no SWAP space).

Attachments (2)

mfile.C.diff (1.9 KB) - added by Joses 17 years ago.
highlight several realloc() functions that should handle existing "buf"
parse.C.diff (453 bytes) - added by Joses 17 years ago.
lib/parse.C has a similar problem - highlighted realloc()==NULL

Download all attachments as: .zip

Change History (7)

Changed 17 years ago by Joses

Attachment: mfile.C.diff added

highlight several realloc() functions that should handle existing "buf"

Changed 17 years ago by Joses

Attachment: parse.C.diff added

lib/parse.C has a similar problem - highlighted realloc()==NULL

comment:1 Changed 16 years ago by romw

Owner: changed from romw to davea

comment:2 Changed 15 years ago by davea

Resolution: wontfix
Status: newclosed

It's not clear what problem this fixes

comment:3 Changed 15 years ago by Nicolas

If realloc() fails, BOINC loses the pointer to the original buffer, causing a leak, making the lack-of-memory problem worse.

comment:4 Changed 15 years ago by Joses

Resolution: wontfix
Status: closedreopened

I would consider this just one of the fixes to help harden BOINC a bit more for fault tolerance (especially for machines that have little memory and are misconfigured (especially without any sort of swap file like I've seen on some older linux distros - netbooks could be an example of machines short on memory - and other attributes as well where some sort of sanity check would be of benefit)).

I've seen the number of complains on OpenOffice?'s hunspell drop due to fixes like these (check bugfix #1749709 on sourceforge as an example), and similar alloc and realloc patches for aspell. Realloc is a bit tougher to notice but is fixable too - however, I don't know your preferred stategy with dealing with errors so I left that up to you (I prefer returning stuff back through the stack).

There are also several IO routines that could benefit from some error checks as well, but from experience, it's best to release a few bugs at a time instead of sending in an overwhelming large number of patches - this realloc() being one of several improvement hopefully accepted :-)

comment:5 Changed 15 years ago by davea

Resolution: fixed
Status: reopenedclosed

(In [18594]) - client: if malloc fails in MFILE writes, exit.

We don't check the return values of printf() anywhere, and it's dangerous for the client to continue if it thinks something got written that didn't. Fixes #281

Note: See TracTickets for help on using tickets.