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

Missing cleanup in destructor of libember::ber::AsyncBerReader #12

Closed
GoogleCodeExporter opened this issue Jul 31, 2015 · 7 comments
Closed

Comments

@GoogleCodeExporter
Copy link

I think a call to AsyncBerReader::reset() is required to do the whole cleanup 
in libember::ber::AsyncBerReader::AsyncBerReader~().

Original issue reported on code.google.com by nullable...@gmail.com on 20 Jun 2013 at 7:56

Attachments:

@GoogleCodeExporter
Copy link
Author

You are correct, the current implementation leaks memory when destroyed.

After browsing through the implementation for a bit it appears to me that this 
class could generally use some memory safety lovin', e.g. looking at

void AsyncBerReader::pushContainer()

it's pretty obvious that this method would leak the allocated container in case 
of m_stack.push() throwing an exception.

@Marius: Could you have a look at this? Otherwise you can assign this issue to 
me and I'll fix it in the next few days, after grasping the intended sematics 
of the reader implementation.

Original comment by Kimon.Ho...@lawo.com on 20 Jun 2013 at 10:35

@GoogleCodeExporter
Copy link
Author

Yes, I will take a look at this issue and fix it today or tomorrow latest.

Original comment by marius.k...@l-s-b.de on 25 Jun 2013 at 9:08

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

This issue was closed by revision r31.

Original comment by marius.k...@l-s-b.de on 27 Jun 2013 at 10:46

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

The destructor now calls the reset() method and AsyncBerReader::pushContainer 
catches any exceptions during the memory allocation and the push operation.

Original comment by marius.k...@l-s-b.de on 27 Jun 2013 at 10:47

@GoogleCodeExporter
Copy link
Author

Regarding the changes of r31 inside void AsyncBerReader::pushContainer():

1.) I think translating the exception is not a big benefit and i think 
rethrowing the exception (by just throw;) would be better.
2.) In my opinion, the code would be much more smarter with RAII (something 
like boost::scoped_ptr or std::unique_ptr, maybe simpler).

Are there opinions on that?

Original comment by nullable...@gmail.com on 27 Jun 2013 at 12:53

@GoogleCodeExporter
Copy link
Author

I also think a solution based on RAII should (always) be preferred.
But in this case std::auto_ptr<> should be used instead of std::unique_ptr<> or 
boost::scoped_ptr<>, because we base libember solely on C++03 at the meoment.

Original comment by Kimon.Ho...@lawo.com on 27 Jun 2013 at 2:15

@GoogleCodeExporter
Copy link
Author

I changed the class to use std::auto_ptr, but it was necessary to remove the 
member pointing to the current container, so some further testing is required 
but it looks good so far. Please take a look at it if possible.

Original comment by marius.k...@l-s-b.de on 28 Jun 2013 at 4:23

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

No branches or pull requests

1 participant