Skip to content

Commit

Permalink
Merge pull request #95 from ctabin/fix-minor-leaks
Browse files Browse the repository at this point in the history
Fix minor leaks
  • Loading branch information
ctabin authored Feb 13, 2021
2 parents 791bdc4 + 59ac792 commit ab75650
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ clean-tests:
@rm -rf *.zip

tests: libzippp-tests clean-tests
LD_LIBRARY_PATH="$(LIBZIP)/build/lib" valgrind --suppressions=ld.supp ./test_shared
valgrind --suppressions=ld.supp ./test_static
LD_LIBRARY_PATH="$(LIBZIP)/build/lib" valgrind --suppressions=ld.supp --leak-check=full ./test_shared
valgrind --suppressions=ld.supp --leak-check=full ./test_static

clean:
@rm -rf libzippp.a libzippp.so
Expand Down
12 changes: 6 additions & 6 deletions src/libzippp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ bool ZipArchive::open(OpenMode om, bool checkConsistency) {
zipHandle = zip_open(path.c_str(), zipFlag, &errorFlag);

//error during opening of the file
if(errorFlag!=ZIP_ER_OK) {
if (errorFlag!=ZIP_ER_OK) {
/*char* errorStr = new char[256];
zip_error_to_str(errorStr, 255, errorFlag, errno);
errorStr[255] = '\0';
Expand Down Expand Up @@ -208,17 +208,17 @@ bool ZipArchive::open(OpenMode om, bool checkConsistency) {
int ZipArchive::close(void) {
if (isOpen()) {

if (zipSource){
//zip_source_close(zipSource);
//zip_source_free(zipSource);
//zipSource = nullptr;
if (zipSource) {
//no free here because it should not be done once successfully used in zip_open_from_source
zip_source_close(zipSource);
zipSource = nullptr;
}

int result = zip_close(zipHandle);
zipHandle = nullptr;
mode = NotOpen;

if(result!=0) { return result; }
if (result!=0) { return result; }
}

return LIBZIPPP_OK;
Expand Down
2 changes: 2 additions & 0 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ void test21() {
z2->close();
delete z2;

free(buffer);

cout << " done." << endl;
}

Expand Down

0 comments on commit ab75650

Please sign in to comment.