You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "Lee Doron (Commented) (JIRA)" <xe...@xml.apache.org> on 2011/12/01 23:00:40 UTC

[jira] [Commented] (XERCESC-1974) Memory leak occurs if an exception is thrown in TranscodeToStr or TranscodeFromStr constructors

    [ https://issues.apache.org/jira/browse/XERCESC-1974?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13161226#comment-13161226 ] 

Lee Doron commented on XERCESC-1974:
------------------------------------

By the way, two more notes. First, I noticed inconsistent usage of tabs and spaces for indentation in the transcode() methods. I didn't want to muddy up the patch with whitespace changes, but you might want to clean that up (I personally suggest spaces, but that can be a religious issue ;-) ).

Second, I also have a slightly different approach to fixing this, that I originally started out with. Instead of using a local ArrayJanitor<XMLByte> (or XMLCh) template object to shadow fString, I actually changed the type of fString from a simple pointer to ArrayJanitor<XMLByte>. This means a few more changes here and in TransService.hpp, but it lets ArrayJanitor do more of the work.

It's really just a matter of style -- both approaches work equally well. If you want to keep the changes to a minimum, this patch is the one you want; if you want to clean up a bit, my other fix might be worth considering. Let me know if you're interested, and I will gladly post that as a patch, too.

                
> Memory leak occurs if an exception is thrown in TranscodeToStr or TranscodeFromStr constructors
> -----------------------------------------------------------------------------------------------
>
>                 Key: XERCESC-1974
>                 URL: https://issues.apache.org/jira/browse/XERCESC-1974
>             Project: Xerces-C++
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 3.1.1
>         Environment: Any
>            Reporter: Lee Doron
>              Labels: patch
>             Fix For: 3.1.2, 3.2.0, 4.0.0
>
>         Attachments: TransService.cpp.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The constructor for TranscodeToStr calls TranscodeToStr::transcode(). That method allocates memory for fString, but it is possible for an exception to occur shortly thereafter; it might be thrown directly by transcode(), or by the transcoder method call trans->transcodeTo(). Since we are still in the constructor, TranscodeToStr's destructor will not be called during the stack unwind to clean up (see http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.10 ). Therefore, we have to explicitly make sure fString will be deallocated. Since the current code doesn't do that, it leaks memory. TranscodeFromStr is in the same situation.
> I have a simple patch that I expect to post later tonight.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org