-
Notifications
You must be signed in to change notification settings - Fork 124
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
Memory leaks in Zipper & Unzipper #16
Comments
@oranja thanks for fixing this, i'm glad that you've found zipper helpful. I do have some objections here. The initialization fixes look good, but i personally don't like having pointers around, and that was the main reason for methods to extract references instead of receiving pointers. So, I would prefer to keep it that way. Regarding the other changes on the code, some related to types and date handling, Are you sure those wont break in other platforms? this code was changed in order to run on multiple environments, linux, iOS, windows, embedded systems, etc. I would only add the changes related to the memory leak fix, unless we are 100% sure the others doesn't break compilation, since we don't have zipper configured on travis yet (I would love if someone with experience configuring travis for c++ could help here) @fbergmann what do you think about this? Anyway, if you agree, please go ahead and make a PR with the memory leak only fixes. Thanks again! |
I personally don't like working with raw pointers either, The way I see it, by taking a reference to an external object we're taking a risk, and the least sensible thing to do would be to hide this risk. References always seem safer, but here I don't think it's the case. Alternatively, and maybe even more ideally, streams and buffers can be asked by the library only when they are really needed, so the API would look more like: Zipper::Zipper(istream &input_stream) {
// init in-memory zip from stream - exactly how it works now
// but don't keep the stream after that.
}
Zipper::add(istream& input_stream) {
// compress and add to in-memory zip structure
}
Zipper::write(ostream &output_stream) {
// write the entire in-memory zip structure to the given output stream
}
Zipper::close() {
// clear the in-memory data. hopefully the data was written somewhere earlier.
} File operations can be easy with a few convience methods that create streams from files and even complete directories. Anyway, this is a complete overhaul of the API, and naturally it's a tougher decision and change to make. As for the timestamp handling: |
I'm following this thread because I also confirm memory leaks and found interesting the talk about "references vs pointers as members":
PS:
I may help if you still want CI. zipper works in Travis for ubuntu and OS X. Concerning appveyor, I did not make progress. |
@oranja @Lecrapouille Guys, first of all, thanks for taking the time to contribute and improve the library. What do you think? If I see two thumbs up, ill create a new issue for the new fork where we can discuss the implementation details/interface changes Thanks! |
I'm not expert in c++17 but not all compilers are c++17 ready, so you'll limit yourself to some compiler / architecture. Look: http://en.cppreference.com/w/cpp/compiler_support
Yes !! In addition we are drifting to another subject than memory leaks. |
My main argument against having a fork at this point is that I don't think we have enough coding force here to maintain two forks. Besides, IMHO, the current code base is not far enough from good shape that it justifies starting from scratch over fixing a few issues. Now, it's a real mystery how C++ leads the industry all these years without even the most basic path manipulation utility, but I think first priority should be to get the current non-C++17 version to work well. I would consider C++11, though. It is already supported by the major compilers enough for our needs - mainly smart pointers. Perhaps a separate issue dedicated to this discussion would be best, as suggested. p.s. |
Although i haven't seen the thumbs up 😃 , I've created #24 to continue the discussion |
I can take a moment for solving memory links based on Oranja's work. I made a quick look at both code and now I understand better why oranja wanted use pointers. In current zipper code, in constructors there is a mixture between references to external objects and references to allocated internal members, making impossible to call delete (without additional informations). Look:
versus:
With the 1st constructor: we have to call delete in the destructor to release memory, but this will crash with the second constructor. For the moment, I did look in deep the code so I don't know if we can make a simple copy of std::vector buffer or std::iostream& buffer inside class members. PS: std::iostream cannot be copied or moved :( |
I may found a fix. I will create a PR. |
Hi,
First of all, thanks for this library.
I need some pretty straightforward zip file manipulation (take an existing zip, add a file from memory stream, close), and this helps me do it with 3 simple and straightforward code lines that read exactly that story (ctor/open, add, close).
While testing for any memory leaks in my program (with
valgrind
), I found out that I have some small memory leaks any time I do this process, and I pinned it down to Zipper.I fixed the code enough that my
Zipper
use case does not leak anymore, and the test doesn't show any other leaks inZipper
.However the
valgrind
test shows leaks in Unzipper too. I made some changes there, but not enough to fix all leaks apparently.If you want to take a look at the changes I made, take a look at oranja/zipper, but note that (a) it's not a complete solution, and (b) I also made changes to use the latest
minizip
code from nmoinvaz. This is why I didn't create a PR yet.The text was updated successfully, but these errors were encountered: