Skip to content

Commit

Permalink
Make a copy of a prefix param in StartIteration
Browse files Browse the repository at this point in the history
and delete it in EndIteration.

Change-Id: I4de4167700a9dba3119fde22fcd45725742f3731
  • Loading branch information
Piotr Jastrzebski committed Aug 11, 2014
1 parent 400e737 commit 34e03bd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libziparchive/zip_archive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -899,10 +899,12 @@ int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, const char* p

IterationHandle* cookie = (IterationHandle*) malloc(sizeof(IterationHandle));
cookie->position = 0;
cookie->prefix = prefix;
cookie->archive = archive;
if (prefix != NULL) {
cookie->prefix = strdup(prefix);
cookie->prefix_len = strlen(prefix);
} else {
cookie->prefix = NULL;
}

*cookie_ptr = cookie ;
Expand All @@ -911,6 +913,10 @@ int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, const char* p

void EndIteration(void* cookie) {
if (cookie != NULL) {
IterationHandle* handle = reinterpret_cast<IterationHandle*>(cookie);
if (handle->prefix != NULL) {
free(const_cast<char*>(handle->prefix));
}
free(cookie);
}
}
Expand Down

0 comments on commit 34e03bd

Please sign in to comment.