Re: [patch] Add Logging Support for SID Components

Dave Brolley <[email protected]>
Newsgroups gmane.comp.emulators.sid.devel
Message-ID <[email protected]>

Frank Ch. Eigler wrote:

>The new version seems to have at least one actual problem though:
>the way that the buffer array is managed.  Its allocation/deallocation
>strategy should be consistent (probably "new char[]" and "delete[] char")
>regardless of the availability of the various *sprintf variants.  It should
>probably not even be in #if/#endif markers.  The new code appears to be
>able to hit free() even though malloc() was never called.
>  
>
The piece of information that you're probably missing is that vasprintf 
automatically allocates a buffer of the proper size each time it is 
called and it uses malloc. Thus free () is only called when using 
vasprintf (! HAVE_VSNPRINTF && HAVE_VASPRINTF). Otherwise 
(HAVE_VSNPRINTF || ! HAVE_VAPRINTF) a persistent buffer is used  which 
can be grown if necessary only when vsnprintf is used. I chose to use 
new/delete here since I had a choice.

I have reviewed the code again and believe that it is correct. I can get 
the call to free() out of #if/#endif if I allocate a buffer everytime 
for all alternatives using malloc, but conditional compilation would 
still be necessary for the allocations/growth.

Let me know if you feel these changes are necessary.

Thanks,
Dave
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.