LWN.net Logo

code feedback ...

code feedback ...

Posted Sep 16, 2011 13:43 UTC (Fri) by renox (subscriber, #23785)
In reply to: code feedback ... by vapier
Parent article: Ensuring data reaches disk

> you forgot to free(buf) after the while loop and in the early returns inside of the loop. might as well just use the stack: char buf[MY_BUF_SIZE];

Is-it such a good idea?
I though that it was better to keep the stack small.


(Log in to post comments)

code feedback ...

Posted Sep 16, 2011 19:17 UTC (Fri) by bronson (subscriber, #4806) [Link]

That was painfully true 20 years ago. With modern memory management it doesn't matter much. Within reason of course -- a 20 MB buffer should probably still go on the heap.

code feedback ...

Posted Jan 25, 2012 20:34 UTC (Wed) by droundy (subscriber, #4559) [Link]

I prefer to avoid putting buffers on the stack simply to reduce the difficulties associated with buffer overflows. Not for security reasons (most of my programming is scientific), but simply so overwriting the buffer won't trash the stack, making debugging harder. And also to allow valgrind to immediately recognize a buffer overwrite...

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds