Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XERCESC-2233] DFAContentModel::buildDFA(): fix memory leaks when OutOfMemoryException occurs #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rouault
Copy link
Contributor

@rouault rouault commented Dec 4, 2021

@rouault rouault changed the title DFAContentModel::buildDFA(): fix memory leaks when OutOfMemoryException occurs [XERCESC-2233] DFAContentModel::buildDFA(): fix memory leaks when OutOfMemoryException occurs Dec 4, 2021
}
catch( const OutOfMemoryException& e )
{
oomException = e;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How safe is the saving and re-throwing of the exception? Is there any potential for OutOfMemoryException& e to be a reference to a base class? Could e end up being truncated as a result? A direct throw to rethrow the existing exception might be safer overall, and avoid the need for a goto.

Could we achieve the same effect with a higher-level try/catch block within the function, and avoid the saving of the exception and the goto?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly. I didn't want to change the code too much. Your suggestion will probably involve moving the cleanup code in a lambda function that will be called at the end of the nominal code path and in the catch() block.

@rouault
Copy link
Contributor Author

rouault commented Dec 5, 2021

I've updated the commit with the above strategy I mentioned in #44 (comment). The diff might be hard to read because of the indentation changes, but the changes themselves are relatively simple and consist in:

@scantor
Copy link
Contributor

scantor commented Oct 5, 2022

I saw mention of a lambda? I would have to imagine that's out of bounds for the branch given the need for older compiler support, though I may be wrong on that. This is a pretty huge patch to code I don't know so I'd be reluctant. Is the original smaller patch at least enough of an improvement to consider?

@rouault
Copy link
Contributor Author

rouault commented Oct 5, 2022

I believe the original patch was rouault@f7e7633 . I guess it is equivalent to the new one, but my memory may lie

@scantor
Copy link
Contributor

scantor commented Oct 6, 2022

Given that this is just fixing a memory leak in a case where the process is going to die anyway, I'm inclined to leave it out of the branch and this patch release. That's not a good enough reason to make a non-trivial change to code I don't know at all. Can always revisit later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants