|
From: Per W. <pw...@ia...> - 2003-04-01 14:30:02
|
free() ignores the contents of your array. All you need is the pointer you originally received from malloc() or calloc(). free() will then release the full block - unless you for some reason has managed to break the heap by writing outside of the allocated area (or actually to write immediately BEFORE the returned pointer) and thereby destroy the heap management that is almost always part of the allocated memory block. /Per W On Tue, 1 Apr 2003, Luigi Santillo wrote: > On Tue, Apr 01, 2003 at 11:37:28AM +0200, Per Westermark wrote: > > Your implementation of itoa would leak memory - normally itoa would use a > > static buffer that is overwritten at each call. > > I agree that mine is just a try, also I wish to learn from your > comment. My code has a memory leak because of: > - user will almost always forget to call "free" (shortly: bad designed code) > - there is a bug in the code (shortly: bugged code) > - both bad design and bad code > > By the way, a call to "strcpy" does copy the piece of an array up-to > the '\0', does the function "free" return memory up-to the '\0' or does > it free the whole array (as I assume) ? > > > > A better itoa would build the buffer from the end, i.e. *p-- = ch > > thereby removing need for reversing the string. > > I'll try to follow this advice too. > > > /Per W > > Thanks Per > -- > >> gisan >> > > > ------------------------------------------------------- > This SF.net email is sponsored by: ValueWeb: > Dedicated Hosting for just $79/mo with 500 GB of bandwidth! > No other company gives more support or power for your dedicated server > http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |