From 34e03bdfdf3defc667eab68f126ad3370547159a Mon Sep 17 00:00:00 2001 From: Piotr Jastrzebski Date: Fri, 8 Aug 2014 15:59:12 +0100 Subject: [PATCH] Make a copy of a prefix param in StartIteration and delete it in EndIteration. Change-Id: I4de4167700a9dba3119fde22fcd45725742f3731 --- libziparchive/zip_archive.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc index 366fb243f..a29eb79d8 100644 --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc @@ -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 ; @@ -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(cookie); + if (handle->prefix != NULL) { + free(const_cast(handle->prefix)); + } free(cookie); } }